Skip to content

Commit

Permalink
fix(compile): avoid direct import of dev deps
Browse files Browse the repository at this point in the history
  • Loading branch information
nfroidure committed Sep 25, 2021
1 parent 70a8387 commit 8db9dbe
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
11 changes: 7 additions & 4 deletions packages/whook/src/services/compiler.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import path from 'path';
import * as esbuild from 'esbuild';
import * as esbuildNodeExternals from 'esbuild-node-externals';
import initCompiler from './compiler';

describe('Compiler', () => {
Expand All @@ -17,7 +18,8 @@ describe('Compiler', () => {
});

test('should work with external modules', async () => {
importer.mockResolvedValue(esbuild);
importer.mockResolvedValueOnce(esbuild);
importer.mockResolvedValueOnce(esbuildNodeExternals);

const compiler = await initCompiler({
PROJECT_DIR,
Expand All @@ -37,15 +39,16 @@ describe('Compiler', () => {
logCalls: log.mock.calls,
}).toMatchInlineSnapshot(`
Object {
"contentsLength": 121905,
"contentsLength": 90265,
"logCalls": Array [],
"mappingsLength": 0,
}
`);
});

test('should work with code only', async () => {
importer.mockResolvedValue(esbuild);
importer.mockResolvedValueOnce(esbuild);
importer.mockResolvedValueOnce(esbuildNodeExternals);

const compiler = await initCompiler({
PROJECT_DIR,
Expand All @@ -65,7 +68,7 @@ describe('Compiler', () => {
logCalls: log.mock.calls,
}).toMatchInlineSnapshot(`
Object {
"contentsLength": 5066,
"contentsLength": 5024,
"logCalls": Array [],
"mappingsLength": 0,
}
Expand Down
2 changes: 1 addition & 1 deletion packages/whook/src/services/compiler.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import path from 'path';
import { noop } from '../libs/utils';
import { autoService } from 'knifecycle';
import { nodeExternalsPlugin } from 'esbuild-node-externals';
import type { LogService } from 'common-services';
import type { BuildOptions } from 'knifecycle/dist/build';
import type { ImporterService } from '..';
Expand Down Expand Up @@ -52,6 +51,7 @@ async function initCompiler({
log = noop,
}: WhookCompilerDependencies): Promise<WhookCompilerService> {
const { build } = await importer('esbuild');
const { nodeExternalsPlugin } = await importer('esbuild-node-externals');

return async function compiler(
entryPoint: string,
Expand Down

0 comments on commit 8db9dbe

Please sign in to comment.