-
Notifications
You must be signed in to change notification settings - Fork 71
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(bundle-source): Add
tag
command-line flag
- Loading branch information
Showing
12 changed files
with
144 additions
and
6 deletions.
There are no files selected for viewing
This file contains 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 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
1 change: 1 addition & 0 deletions
1
packages/bundle-source/demo/node_modules/conditional-exports/a.js
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
1 change: 1 addition & 0 deletions
1
packages/bundle-source/demo/node_modules/conditional-exports/b.js
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
9 changes: 9 additions & 0 deletions
9
packages/bundle-source/demo/node_modules/conditional-exports/package.json
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
2 changes: 2 additions & 0 deletions
2
packages/bundle-source/demo/node_modules/conditional-reexports/entry.js
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
8 changes: 8 additions & 0 deletions
8
packages/bundle-source/demo/node_modules/conditional-reexports/package.json
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains 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 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 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 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 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,67 @@ | ||
/* global Buffer */ | ||
import test from '@endo/ses-ava/prepare-endo.js'; | ||
|
||
import { spawn } from 'child_process'; | ||
import url from 'url'; | ||
|
||
const textDecoder = new TextDecoder(); | ||
|
||
const cwd = url.fileURLToPath(new URL('..', import.meta.url)); | ||
|
||
const bundleSource = async (...args) => { | ||
const bundleBytes = await new Promise((resolve, reject) => { | ||
const errorChunks = []; | ||
const outputChunks = []; | ||
const child = spawn('node', ['bin/bundle-source', ...args], { | ||
cwd, | ||
stdio: ['inherit', 'pipe', 'pipe'], | ||
}); | ||
child.on('close', code => { | ||
if (code !== 0) { | ||
reject( | ||
new Error( | ||
`Exit code: ${code}\nError output: ${new TextDecoder().decode( | ||
Buffer.concat(errorChunks), | ||
)}`, | ||
), | ||
); | ||
} else { | ||
resolve(Buffer.concat(outputChunks)); | ||
} | ||
}); | ||
child.stdout.on('data', chunk => { | ||
outputChunks.push(chunk); | ||
}); | ||
child.stderr.on('data', chunk => { | ||
errorChunks.push(chunk); | ||
}); | ||
}); | ||
const bundleText = textDecoder.decode(bundleBytes); | ||
return JSON.parse(bundleText); | ||
}; | ||
|
||
test('bundle-source with --format and --tag', async t => { | ||
const compartment = new Compartment(); | ||
{ | ||
const bundle = await bundleSource( | ||
'--tag', | ||
'b', | ||
'--format', | ||
'endoScript', | ||
'demo/node_modules/conditional-reexports/entry.js', | ||
); | ||
const namespace = compartment.evaluate(bundle.source); | ||
t.is(namespace.default, 'b'); | ||
} | ||
{ | ||
const bundle = await bundleSource( | ||
'--tag', | ||
'a', | ||
'--format', | ||
'endoScript', | ||
'demo/node_modules/conditional-reexports/entry.js', | ||
); | ||
const namespace = compartment.evaluate(bundle.source); | ||
t.is(namespace.default, 'a'); | ||
} | ||
}); |