Repository navigation
fix: publish source files referenced by source conditional exports #10607
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
Tyagiquamar
wants to merge
8
commits into
adobe:main
Choose a base branch
from
Tyagiquamar:fix/source-export-resolution
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
3af72be
fix: publish source files referenced by source conditional exports
Tyagiquamar 146aef7
fix: omit source conditions in published packages via publishConfig
Tyagiquamar 4493572
Merge branch 'main' into fix/source-export-resolution
snowystinger 87a9622
fix: strip source references when packing published packages
Tyagiquamar ea33b58
chore: restore original manifest key order to minimize diff
Tyagiquamar a2b920e
test: allow the packing fixture to create its lockfile in CI
Tyagiquamar 0cf1005
Merge branch 'main' into fix/source-export-resolution
Tyagiquamar 4c859c3
Merge branch 'main' into fix/source-export-resolution
Tyagiquamar File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,117 @@ | ||
| const fs = require('fs'); | ||
| const os = require('os'); | ||
| const path = require('path'); | ||
| const {execFileSync} = require('child_process'); | ||
| const tar = require('tar'); | ||
|
|
||
| const root = path.resolve(__dirname, '../../..'); | ||
| const yarn = path.join(root, '.yarn/releases/yarn-4.18.0.cjs'); | ||
| const helper = path.join(root, 'scripts/prepareForPublish.js'); | ||
| const names = ['react-aria', 'react-stately', 'react-aria-components']; | ||
| let fixture; | ||
| const originals = new Map(); | ||
|
|
||
| beforeAll(() => { | ||
| fixture = fs.mkdtempSync(path.join(os.tmpdir(), 'spectrum-pack-')); | ||
| fs.writeFileSync( | ||
| path.join(fixture, 'package.json'), | ||
| JSON.stringify({private: true, workspaces: ['packages/*']}) | ||
| ); | ||
| for (let name of names) { | ||
| let manifest = JSON.parse(fs.readFileSync(path.join(root, 'packages', name, 'package.json'))); | ||
| delete manifest.dependencies; | ||
| delete manifest.devDependencies; | ||
| delete manifest.peerDependencies; | ||
| manifest.scripts = { | ||
| prepack: `node "${helper}" prepare`, | ||
| postpack: `node "${helper}" restore` | ||
| }; | ||
| let dir = path.join(fixture, 'packages', name); | ||
| fs.mkdirSync(path.join(dir, 'exports'), {recursive: true}); | ||
| fs.mkdirSync(path.join(dir, 'src')); | ||
| fs.mkdirSync(path.join(dir, 'dist/exports'), {recursive: true}); | ||
| fs.writeFileSync(path.join(dir, 'exports/index.ts'), 'export const source = true;'); | ||
| fs.writeFileSync(path.join(dir, 'src/index.ts'), 'export const source = true;'); | ||
| fs.writeFileSync(path.join(dir, 'dist/exports/index.mjs'), 'export const built = true;'); | ||
| let contents = JSON.stringify(manifest, null, 2) + '\n'; | ||
| originals.set(name, contents); | ||
| fs.writeFileSync(path.join(dir, 'package.json'), contents); | ||
| } | ||
| execFileSync(process.execPath, [yarn, 'install', '--mode=skip-build'], { | ||
| cwd: fixture, | ||
| env: {...process.env, YARN_ENABLE_IMMUTABLE_INSTALLS: 'false'}, | ||
| stdio: 'inherit' | ||
| }); | ||
| }, 120000); | ||
|
|
||
| afterAll(() => { | ||
| fs.rmSync(fixture, {recursive: true, force: true}); | ||
| }); | ||
|
|
||
| async function checkArchive(name, archive) { | ||
| let entries = []; | ||
| await tar.list({file: archive, onReadEntry: entry => entries.push(entry.path)}); | ||
| expect(entries.some(entry => /^package\/(src|exports)\//.test(entry))).toBe(false); | ||
| let destination = fs.mkdtempSync(path.join(fixture, 'unpacked-')); | ||
| await tar.extract({file: archive, cwd: destination}); | ||
| let manifest = JSON.parse(fs.readFileSync(path.join(destination, 'package/package.json'))); | ||
| let original = JSON.parse(originals.get(name)); | ||
| expect(manifest.source).toBeUndefined(); | ||
| for (let [key, conditions] of Object.entries(original.exports)) { | ||
| if (conditions && typeof conditions === 'object') { | ||
| let expected = {...conditions}; | ||
| delete expected.source; | ||
| expect(manifest.exports[key]).toEqual(expected); | ||
| } else { | ||
| expect(manifest.exports[key]).toEqual(conditions); | ||
| } | ||
| } | ||
| expect(fs.readFileSync(path.join(fixture, 'packages', name, 'package.json'), 'utf8')).toBe( | ||
| originals.get(name) | ||
| ); | ||
| expect( | ||
| fs.existsSync(path.join(fixture, 'packages', name, 'exports/.package-json-before-pack')) | ||
| ).toBe(false); | ||
| } | ||
|
|
||
| test.each(names)( | ||
| 'npm packing %s omits source references and restores local resolution', | ||
| async name => { | ||
| let dir = path.join(fixture, 'packages', name); | ||
| execFileSync('npm', ['pack', '--pack-destination', dir], {cwd: dir}); | ||
| let archive = fs.readdirSync(dir).find(file => file.endsWith('.tgz')); | ||
| await checkArchive(name, path.join(dir, archive)); | ||
| fs.unlinkSync(path.join(dir, archive)); | ||
| }, | ||
| 120000 | ||
| ); | ||
|
|
||
| test.each(names)( | ||
| 'Yarn packing %s omits source references and restores local resolution', | ||
| async name => { | ||
| let dir = path.join(fixture, 'packages', name); | ||
| let archive = path.join(fixture, `${name}-yarn.tgz`); | ||
| execFileSync(process.execPath, [yarn, 'pack', '--out', archive], {cwd: dir}); | ||
| await checkArchive(name, archive); | ||
| }, | ||
| 120000 | ||
| ); | ||
|
|
||
| test('direct Verdaccio seeding strips source in tarballs and registry manifests', async () => { | ||
| let storage = path.join(fixture, 'storage'); | ||
| let input = names.map(name => JSON.stringify({name, location: `packages/${name}`})).join('\n'); | ||
| execFileSync(process.execPath, [path.join(root, 'scripts/verdaccio-seed.js'), storage], { | ||
| cwd: fixture, | ||
| input | ||
| }); | ||
| for (let name of names) { | ||
| let dir = path.join(storage, name); | ||
| let archive = fs.readdirSync(dir).find(file => file.endsWith('.tgz')); | ||
| await checkArchive(name, path.join(dir, archive)); | ||
| let registry = JSON.parse(fs.readFileSync(path.join(dir, 'package.json'))); | ||
| let manifest = Object.values(registry.versions)[0]; | ||
| expect(manifest.source).toBeUndefined(); | ||
| expect(manifest.exports['.'].source).toBeUndefined(); | ||
| expect(manifest.exports['./*'].source).toBeUndefined(); | ||
| } | ||
| }, 120000); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,30 @@ | ||
| 'use strict'; | ||
|
|
||
| const fs = require('fs'); | ||
| const path = require('path'); | ||
|
|
||
| function prepare(dir) { | ||
| let manifestPath = path.join(dir, 'package.json'); | ||
| let contents = fs.readFileSync(manifestPath, 'utf8'); | ||
| let manifest = JSON.parse(contents); | ||
| fs.writeFileSync(path.join(dir, 'exports', '.package-json-before-pack'), contents, {flag: 'wx'}); | ||
| delete manifest.source; | ||
| for (let conditions of Object.values(manifest.exports)) { | ||
| if (conditions && typeof conditions === 'object') { | ||
| delete conditions.source; | ||
| } | ||
| } | ||
| fs.writeFileSync(manifestPath, JSON.stringify(manifest, null, 2) + '\n'); | ||
| } | ||
|
|
||
| function restore(dir) { | ||
| let backup = path.join(dir, 'exports', '.package-json-before-pack'); | ||
| fs.writeFileSync(path.join(dir, 'package.json'), fs.readFileSync(backup)); | ||
| fs.unlinkSync(backup); | ||
| } | ||
|
|
||
| module.exports = {prepare, restore}; | ||
|
|
||
| if (require.main === module) { | ||
| module.exports[process.argv[2]](process.cwd()); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why were changes needed in this file? shouldn't the "prepareForPublish" handle it?