Skip to content

Commit

Permalink
fix #1545: "watch" is not allowed with "buildSync"
Browse files Browse the repository at this point in the history
  • Loading branch information
evanw committed Aug 26, 2021
1 parent c4ab224 commit 68af591
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
2 changes: 2 additions & 0 deletions lib/npm/node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -416,8 +416,10 @@ let startWorkerThreadService = (worker_threads: typeof import('worker_threads'))
if (!options) return
let plugins = options.plugins
let incremental = options.incremental
let watch = options.watch
if (plugins && plugins.length > 0) throw fakeBuildError(`Cannot use plugins in synchronous API calls`);
if (incremental) throw fakeBuildError(`Cannot use "incremental" with a synchronous build`);
if (watch) throw fakeBuildError(`Cannot use "watch" with a synchronous build`);
};

// MessagePort doesn't copy the properties of Error objects. We still want
Expand Down
18 changes: 18 additions & 0 deletions scripts/js-api-tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -4121,6 +4121,24 @@ ${path.relative(process.cwd(), input).replace(/\\/g, '/')}:1:2: error: Unexpecte
}
},

async buildSyncWatchThrow({ esbuild, testDir }) {
try {
const input = path.join(testDir, 'in.js')
const output = path.join(testDir, 'out.js')
await writeFileAsync(input, '1+')
esbuild.buildSync({ entryPoints: [input], bundle: true, outfile: output, format: 'cjs', logLevel: 'silent', watch: true })
const result = require(output)
assert.strictEqual(result.default, 123)
assert.strictEqual(result.__esModule, true)
throw new Error('Expected an error to be thrown');
} catch (error) {
assert(error instanceof Error, 'Must be an Error object');
assert.strictEqual(error.message, `Build failed with 1 error:\nerror: Cannot use "watch" with a synchronous build`);
assert.strictEqual(error.errors.length, 1);
assert.strictEqual(error.warnings.length, 0);
}
},

async transformThrow({ esbuild }) {
try {
await esbuild.transform(`1+`, {})
Expand Down

0 comments on commit 68af591

Please sign in to comment.