Skip to content

Commit 1ef83dc

Browse files
TooTallNateVaguelySerious
authored andcommitted
[builders] Fix Node.js builtin imports being relativized in step bundles (#1644)
1 parent 8890b33 commit 1ef83dc

3 files changed

Lines changed: 42 additions & 0 deletions

File tree

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@workflow/builders": patch
3+
---
4+
5+
Fix Node.js builtin imports being relativized in step bundles

packages/builders/src/swc-esbuild-plugin.test.ts

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,42 @@ describe('createSwcPlugin externalizeNonSteps', () => {
122122
expect(output).not.toContain('@/lib/config');
123123
});
124124

125+
it('does not relativize Node.js builtin imports', async () => {
126+
const outdir = join(testRoot, 'out');
127+
const srcDir = join(testRoot, 'src');
128+
const stepFile = join(srcDir, 'step.ts');
129+
130+
writeFile(
131+
stepFile,
132+
`import { createHash } from 'crypto';\nimport { join } from 'node:path';\nconsole.log(createHash, join);`
133+
);
134+
135+
const result = await esbuild.build({
136+
entryPoints: [stepFile],
137+
absWorkingDir: testRoot,
138+
outdir,
139+
bundle: true,
140+
format: 'esm',
141+
platform: 'node',
142+
write: false,
143+
plugins: [
144+
createSwcPlugin({
145+
mode: 'step',
146+
entriesToBundle: [stepFile],
147+
outdir,
148+
}),
149+
],
150+
});
151+
152+
expect(result.errors).toHaveLength(0);
153+
const output = result.outputFiles[0].text;
154+
// Builtins should remain as bare specifiers, not relativized paths
155+
expect(output).toMatch(/from\s+["']crypto["']/);
156+
expect(output).toMatch(/from\s+["']node:path["']/);
157+
expect(output).not.toMatch(/from\s+["']\..*crypto["']/);
158+
expect(output).not.toMatch(/from\s+["']\..*node:path["']/);
159+
});
160+
125161
it('does not externalize aliased imports that resolve into node_modules', async () => {
126162
const outdir = join(testRoot, 'out');
127163
const srcDir = join(testRoot, 'src');

packages/builders/src/swc-esbuild-plugin.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,7 @@ export function createSwcPlugin(options: SwcPluginOptions): Plugin {
154154
!!esbuildResult.path && !esbuildResult.errors.length;
155155
const isProjectLocalFile =
156156
didResolve &&
157+
!esbuildResult.external &&
157158
!esbuildResult.path
158159
.replace(/\\/g, '/')
159160
.includes('/node_modules/');

0 commit comments

Comments
 (0)