Skip to content

Commit b38d6e1

Browse files
committed
Use ESM to use top level await and remove catches with exit
1 parent 13e26af commit b38d6e1

15 files changed

+175
-198
lines changed

integration-tests/esbuild/build-and-run.esm-patched-const-banner.js

Lines changed: 0 additions & 33 deletions
This file was deleted.
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
#!/usr/bin/env node
2+
/* eslint-disable no-console */
3+
4+
import esbuild from 'esbuild'
5+
import { spawnSync } from 'child_process'
6+
import commonConfig from './build.esm.common-config.js'
7+
8+
await esbuild.build({
9+
...commonConfig,
10+
banner: {
11+
js: `import { createRequire } from 'module';
12+
import { fileURLToPath } from 'url';
13+
import { dirname } from 'path';
14+
const require = createRequire(import.meta.url);
15+
const __filename = fileURLToPath(import.meta.url);
16+
const __dirname = dirname(__filename);`
17+
}
18+
})
19+
20+
const { status, stdout, stderr } = spawnSync('node', ['out.mjs'])
21+
if (stdout.length) {
22+
console.log(stdout.toString())
23+
}
24+
if (stderr.length) {
25+
console.error(stderr.toString())
26+
}
27+
if (status) {
28+
throw new Error('generated script failed to run')
29+
}
30+
console.log('ok')

integration-tests/esbuild/build-and-run.esm-patched-global-banner.js

Lines changed: 0 additions & 33 deletions
This file was deleted.
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
#!/usr/bin/env node
2+
/* eslint-disable no-console */
3+
4+
import esbuild from 'esbuild'
5+
import { spawnSync } from 'child_process'
6+
import commonConfig from './build.esm.common-config.js'
7+
8+
await esbuild.build({
9+
...commonConfig,
10+
banner: {
11+
js: `import { createRequire } from 'module';
12+
import { fileURLToPath } from 'url';
13+
import { dirname } from 'path';
14+
globalThis.require ??= createRequire(import.meta.url);
15+
globalThis.__filename ??= fileURLToPath(import.meta.url);
16+
globalThis.__dirname ??= dirname(globalThis.__filename);`
17+
}
18+
})
19+
20+
const { status, stdout, stderr } = spawnSync('node', ['out.mjs'])
21+
if (stdout.length) {
22+
console.log(stdout.toString())
23+
}
24+
if (stderr.length) {
25+
console.error(stderr.toString())
26+
}
27+
if (status) {
28+
throw new Error('generated script failed to run')
29+
}
30+
console.log('ok')

integration-tests/esbuild/build-and-run.esm-relying-in-extension.js

Lines changed: 0 additions & 26 deletions
This file was deleted.
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
#!/usr/bin/env node
2+
/* eslint-disable no-console */
3+
4+
import esbuild from 'esbuild'
5+
import { spawnSync } from 'child_process'
6+
import commonConfig from './build.esm.common-config.js'
7+
8+
await esbuild.build({
9+
...commonConfig,
10+
format: undefined
11+
})
12+
13+
const { status, stdout, stderr } = spawnSync('node', ['out.mjs'])
14+
if (stdout.length) {
15+
console.log(stdout.toString())
16+
}
17+
if (stderr.length) {
18+
console.error(stderr.toString())
19+
}
20+
if (status) {
21+
throw new Error('generated script failed to run')
22+
}
23+
console.log('ok')

integration-tests/esbuild/build-and-run.esm-relying-in-format.js

Lines changed: 0 additions & 32 deletions
This file was deleted.
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
#!/usr/bin/env node
2+
/* eslint-disable no-console */
3+
4+
import esbuild from 'esbuild'
5+
import { spawnSync } from 'child_process'
6+
import { renameSync } from 'fs'
7+
import commonConfig from './build.esm.common-config.js'
8+
9+
await esbuild.build({
10+
...commonConfig,
11+
outfile: 'out.js'
12+
})
13+
14+
// to force being executed as module
15+
renameSync('./out.js', './out.mjs')
16+
17+
const { status, stdout, stderr } = spawnSync('node', ['out.mjs'])
18+
if (stdout.length) {
19+
console.log(stdout.toString())
20+
}
21+
if (stderr.length) {
22+
console.error(stderr.toString())
23+
}
24+
if (status) {
25+
throw new Error('generated script failed to run')
26+
}
27+
console.log('ok')

integration-tests/esbuild/build-and-run.esm-relying-in-out-extension.js

Lines changed: 0 additions & 30 deletions
This file was deleted.
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
#!/usr/bin/env node
2+
/* eslint-disable no-console */
3+
4+
import esbuild from 'esbuild'
5+
import { spawnSync } from 'child_process'
6+
import commonConfig from './build.esm.common-config.js'
7+
8+
// output => basic-test.mjs
9+
await esbuild.build({
10+
...commonConfig,
11+
outfile: undefined,
12+
format: undefined,
13+
outdir: './',
14+
outExtension: { '.js': '.mjs' }
15+
})
16+
17+
const { status, stdout, stderr } = spawnSync('node', ['basic-test.mjs'])
18+
if (stdout.length) {
19+
console.log(stdout.toString())
20+
}
21+
if (stderr.length) {
22+
console.error(stderr.toString())
23+
}
24+
if (status) {
25+
throw new Error('generated script failed to run')
26+
}
27+
console.log('ok')

0 commit comments

Comments
 (0)