Skip to content

Commit

Permalink
fix(core): mark all packages as external
Browse files Browse the repository at this point in the history
Add an esbuild plugins which mark all paths,
which do not start with "/", "." or ".." as external.
This should fix import errors in some situations.
  • Loading branch information
sdorra committed Jul 10, 2024
1 parent 819b1ef commit befba40
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 5 deletions.
5 changes: 5 additions & 0 deletions .changeset/fair-chairs-melt.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@content-collections/core": patch
---

mark all packages as external
19 changes: 14 additions & 5 deletions packages/core/src/configurationReader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,19 +46,28 @@ function resolveCacheDir(config: string, options: Options) {
return path.join(path.dirname(config), ".content-collections", "cache");
}

const externalPackagesPlugin = (configPath: string): esbuild.Plugin => ({
name: "external-packages",
setup: (build) => {
const filter = /^[^.\/]|^\.[^.\/]|^\.\.[^\/]/;
build.onResolve({ filter }, ({ path }) => {
const external = !path.includes(configPath);
return { path, external };
});
},
});

async function compile(configurationPath: string, outfile: string) {
const plugins: Array<esbuild.Plugin> = [];
const plugins: Array<esbuild.Plugin> = [
externalPackagesPlugin(configurationPath),
];
if (process.env.NODE_ENV === "test") {
plugins.push(importPathPlugin);
}

await esbuild.build({
entryPoints: [configurationPath],
packages: "external",
external: [
...Object.keys(packageJson.dependencies),
"@content-collections/*",
],
bundle: true,
platform: "node",
format: "esm",
Expand Down
1 change: 1 addition & 0 deletions turbo.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
"dependsOn": ["^test", "^lint"]
},
"dev": {
"dependsOn": ["^build"],
"cache": false,
"persistent": true
}
Expand Down

0 comments on commit befba40

Please sign in to comment.