|
7 | 7 | WORKFLOW_NODE_COMPAT_BANNER, |
8 | 8 | WORKFLOW_NODE_FILENAME_BANNER, |
9 | 9 | WORKFLOW_OPTIONAL_PG_NATIVE_ALIAS, |
| 10 | + WORKFLOW_OPTIONAL_TYPESCRIPT_ALIAS, |
10 | 11 | WORKFLOW_WORLD_TARGET_MODULE, |
11 | 12 | } from '@workflow/builders'; |
12 | 13 | import { workflowTransformPlugin } from '@workflow/rollup'; |
@@ -48,6 +49,7 @@ export function workflowPlugin(options: WorkflowPluginOptions = {}): Plugin[] { |
48 | 49 | alias: { |
49 | 50 | [WORKFLOW_WORLD_TARGET_MODULE]: workflowTargetWorldAlias, |
50 | 51 | 'pg-native': WORKFLOW_OPTIONAL_PG_NATIVE_ALIAS, |
| 52 | + typescript: WORKFLOW_OPTIONAL_TYPESCRIPT_ALIAS, |
51 | 53 | }, |
52 | 54 | }, |
53 | 55 | }; |
@@ -143,9 +145,19 @@ function patchAdapterNodeServerChunks(cwd: string): void { |
143 | 145 | // that already declares either identifier (const/let/var, e.g. a |
144 | 146 | // CJS-interop shim) would produce a duplicate top-level declaration |
145 | 147 | // and crash the server with a SyntaxError at startup. |
146 | | - const referencesFilename = /\b__(?:file|dir)name\b/.test(source); |
| 148 | + // |
| 149 | + // The `(?![\w$])` lookaheads matter: when adapter-node re-bundles the |
| 150 | + // intermediate output, rollup renames colliding declarations to e.g. |
| 151 | + // `__filename$1`. A bare `\b` boundary matches those ($ is not a word |
| 152 | + // character), which made this skip chunks that declare only a RENAMED |
| 153 | + // binding while still referencing the bare `__filename` (observed with |
| 154 | + // the bundled `typescript` compiler pulled in via cosmiconfig — the |
| 155 | + // server crashed at boot with "__filename is not defined"). |
| 156 | + const referencesFilename = /(?<![\w$])__(?:file|dir)name(?![\w$])/.test( |
| 157 | + source |
| 158 | + ); |
147 | 159 | const declaresOwnBinding = |
148 | | - /\b(?:const|let|var)\s+__(?:file|dir)name\b/.test(source); |
| 160 | + /\b(?:const|let|var)\s+__(?:file|dir)name(?![\w$])/.test(source); |
149 | 161 | if (!referencesFilename || declaresOwnBinding) { |
150 | 162 | continue; |
151 | 163 | } |
|
0 commit comments