Skip to content

Commit

Permalink
fix: treat jest dependencies as external
Browse files Browse the repository at this point in the history
  • Loading branch information
noomorph committed Dec 8, 2023
1 parent 740f493 commit 62bc8bf
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 10 deletions.
2 changes: 1 addition & 1 deletion __fixtures__/simple-project/.esbuild-jestrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ module.exports = {
"outExtension": {
".js": ".mjs"
},
"external": ["chalk", "jest-allure2-reporter"],
"external": ["chalk", "dtrace-provider"],
},
"preTransform": (path, contents) => {
if (path.includes('lodash/noop')) {
Expand Down
3 changes: 1 addition & 2 deletions __fixtures__/simple-project/jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,10 @@ module.exports = {
setupFilesAfterEnv: ['lodash/noop'],
reporters: [
'default',
'jest-allure2-reporter',
'<rootDir>/customReporter.js',
],
testMatch: [
'<rootDir>/src/**/*.test.js',
],
testEnvironment: 'jest-allure2-reporter/environment-node',
testEnvironment: 'jest-environment-emit/node',
};
1 change: 1 addition & 0 deletions __fixtures__/simple-project/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
"esbuild": "^0.19.8",
"esbuild-jest-cli": "../..",
"jest": "^29.5.0",
"jest-environment-emit": "^1.0.3",
"jest-allure2-reporter": "^2.0.0-beta.1",
"lodash": "^4.17.21"
}
Expand Down
2 changes: 1 addition & 1 deletion index.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ export async function build(esbuildJestConfig = {}) {
bundle: true,
splitting: true,
metafile: true,
external: externalModules,
outbase: rootDir,
banner: {
js: ESM_REQUIRE_SHIM,
Expand All @@ -88,7 +89,6 @@ export async function build(esbuildJestConfig = {}) {
package: wrapPackageMiddleware(esbuildJestConfig.package),
preTransform: esbuildJestConfig.preTransform,
postTransform: esbuildJestConfig.postTransform,
...(esbuildBaseConfig.external || []),
}),
...(esbuildBaseConfig.plugins || []),
],
Expand Down
17 changes: 12 additions & 5 deletions plugin.mjs
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import { lstat, readdir, readFile, rm, writeFile } from 'node:fs/promises';
import { readFile, writeFile } from 'node:fs/promises';
import { sep, join, resolve } from 'node:path';
import importFrom from 'import-from';
import { convertPathToImport } from "./utils/resolve-module.mjs";
import { isBuiltinReporter } from "./utils/is-builtin-reporter.mjs";
import { mapSourceToOutputFiles } from "./utils/map-inputs-outputs.mjs";
import { moveJsFile } from "./utils/move-js-file.mjs";
import { pruneDirectory } from "./utils/prune-directory.mjs";
import { JEST_DEPENDENCIES } from "./utils/jest-dependencies.mjs";

const passThrough = (filePath, fileContents) => fileContents;

Expand Down Expand Up @@ -127,10 +128,16 @@ export default ({
});

build.onEnd(async (result) => {
const externalDependencies = Object.fromEntries(['jest', ...external].map(dep => {
const packageJson = importFrom.silent(rootDir, dep + '/package.json');
return packageJson ? [dep, packageJson.version] : null;
}).filter(Boolean));
const externalDependencies = Object.fromEntries(
['jest', ...external]
.map(dep => {
if (JEST_DEPENDENCIES.includes(dep)) {
return null;
}

const packageJson = importFrom.silent(rootDir, dep + '/package.json');
return packageJson ? [dep, packageJson.version] : null;
}).filter(Boolean));

await writeFile(join(outdir, 'package.json'), JSON.stringify(packageMiddleware({
name: 'bundled-tests',
Expand Down
1 change: 0 additions & 1 deletion utils/jest-dependencies.mjs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
export const JEST_DEPENDENCIES = [
'jest',
'jest-changed-files',
'jest-circus',
'jest-cli',
Expand Down

0 comments on commit 62bc8bf

Please sign in to comment.