Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions packages/test/src/mocks/workflows-with-process-global.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export async function processGlobalWorkflow(): Promise<number> {
return process.pid;
}
12 changes: 12 additions & 0 deletions packages/test/src/test-bundler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,18 @@ test('moduleMatches works', (t) => {
t.false(moduleMatches('fs', ['foo']));
});

test('An error is thrown when workflow references the process global', async (t) => {
await t.throwsAsync(
bundleWorkflowCode({
workflowsPath: require.resolve('./mocks/workflows-with-process-global'),
}),
{
instanceOf: Error,
message: /is importing the following disallowed modules.*process/s,
}
);
});

async function runPreloadSharedCounter(
t: ExecutionContext,
workerOptions: Pick<WorkerOptions, 'bundlerOptions' | 'workflowBundle' | 'workflowsPath'>
Expand Down
16 changes: 16 additions & 0 deletions packages/worker/src/workflow/bundler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,22 @@ exports.importInterceptors = function importInterceptors() {
},
},
plugins: [
{
apply: (compiler) => {
compiler.hooks.normalModuleFactory.tap('WorkflowCodeBundler', (normalModuleFactory) => {
for (const moduleType of ['javascript/auto', 'javascript/dynamic', 'javascript/esm']) {
normalModuleFactory.hooks.parser.for(moduleType).tap('WorkflowCodeBundler', (parser) => {
const javascriptParser = parser as any;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will need to add import type { javascript } from 'webpack'

Suggested change
normalModuleFactory.hooks.parser.for(moduleType).tap('WorkflowCodeBundler', (parser) => {
const javascriptParser = parser as any;
normalModuleFactory.hooks.parser.for(moduleType).tap('WorkflowCodeBundler', (javascriptParser: javascript.JavascriptParser) => {

javascriptParser.hooks.expression.for('process').tap('WorkflowCodeBundler', () => {
if (!javascriptParser.isVariableDefined('process')) {
this.foundProblematicModules.add('process');
}
});
});
}
});
},
},
// `@temporalio/interceptors-opentelemetry` only requires `@temporalio/workflow` for interceptors that run in workflow context.
// In order to keep `@temporalio/workflow` as an optional peer dependency for `@temporalio/interceptors-opentelemetry`
// we use `workflow-imports` to reexport all required imports from `@temporalio/workflow`.
Expand Down