Skip to content

Commit

Permalink
Fix unresolveable packages (#481)
Browse files Browse the repository at this point in the history
  • Loading branch information
efoken committed Jul 18, 2022
1 parent e9e8ec4 commit 76f0163
Show file tree
Hide file tree
Showing 5 changed files with 60 additions and 10 deletions.
5 changes: 5 additions & 0 deletions .changeset/tough-ligers-kick.md
@@ -0,0 +1,5 @@
---
"@preconstruct/cli": patch
---

Updated `@rollup/plugin-node-resolve` to `^11.2.1` in order to make direct imports resolveable, e.g. packages that use `exports` in their package.json
2 changes: 1 addition & 1 deletion packages/cli/package.json
Expand Up @@ -23,7 +23,7 @@
"@rollup/plugin-alias": "^3.1.1",
"@rollup/plugin-commonjs": "^15.0.0",
"@rollup/plugin-json": "^4.1.0",
"@rollup/plugin-node-resolve": "^9.0.0",
"@rollup/plugin-node-resolve": "^11.2.1",
"@rollup/plugin-replace": "^2.4.1",
"builtin-modules": "^3.1.0",
"chalk": "^4.1.0",
Expand Down
47 changes: 47 additions & 0 deletions packages/cli/src/build/__tests__/other.ts
Expand Up @@ -408,6 +408,53 @@ test("package resolvable but not in deps", async () => {
expect(true).toBe(false);
});

test("package with exports resolvable", async () => {
let tmpPath = await testdir({
"package.json": JSON.stringify({
name: "package-exports-resolvable-but-not-in-deps",
main: "dist/package-exports-resolvable-but-not-in-deps.cjs.js",
"umd:main": "dist/package-exports-resolvable-but-not-in-deps.umd.min.js",
dependencies: {
"@atomico/hooks": "0.0.0",
},
preconstruct: {
umdName: "packageExportsResolvableButNotInDeps",
},
}),
"node_modules/@atomico/hooks/package.json": JSON.stringify({
name: "@atomico/hooks/use-slot",
exports: {
"./use-slot": "./something/use-slot.js",
},
}),
"node_modules/@atomico/hooks/something/use-slot.js": js`
export function useSlot(ref) {
console.log(ref);
}
`,
"src/index.js": js`
import { useSlot } from "@atomico/hooks/use-slot";
export default function useChildren(ref) {
return useSlot(ref);
}
`,
});

await build(tmpPath);

expect(
await getFiles(tmpPath, [
"dist/package-exports-resolvable-but-not-in-deps.umd.min.js",
])
).toMatchInlineSnapshot(`
⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯ dist/package-exports-resolvable-but-not-in-deps.umd.min.js ⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯
!function(e,o){"object"==typeof exports&&"undefined"!=typeof module?module.exports=o():"function"==typeof define&&define.amd?define(o):(e="undefined"!=typeof globalThis?globalThis:e||self).packageExportsResolvableButNotInDeps=o()}(this,(function(){"use strict";return function(e){return function(e){console.log(e)}(e)}}));
//# sourceMappingURL=package-exports-resolvable-but-not-in-deps.umd.min.js.map
`);
});

test("entrypoint outside package directory", async () => {
let tmpPath = await testdir({
"package.json": JSON.stringify({
Expand Down
4 changes: 1 addition & 3 deletions packages/cli/src/build/rollup.ts
Expand Up @@ -187,9 +187,7 @@ export let getRollupConfig = (
extensions: EXTENSIONS,
// only umd builds will actually load dependencies which is where this browser flag actually makes a difference
browser: type === "umd",
customResolveOptions: {
moduleDirectory: type === "umd" ? "node_modules" : [],
},
moduleDirectories: type === "umd" ? ["node_modules"] : [],
}),
type === "umd" && inlineProcessEnvNodeEnv({ sourceMap: true }),
type === "umd" &&
Expand Down
12 changes: 6 additions & 6 deletions yarn.lock
Expand Up @@ -3007,17 +3007,17 @@
dependencies:
"@rollup/pluginutils" "^3.0.8"

"@rollup/plugin-node-resolve@^9.0.0":
version "9.0.0"
resolved "https://registry.yarnpkg.com/@rollup/plugin-node-resolve/-/plugin-node-resolve-9.0.0.tgz#39bd0034ce9126b39c1699695f440b4b7d2b62e6"
integrity sha512-gPz+utFHLRrd41WMP13Jq5mqqzHL3OXrfj3/MkSyB6UBIcuNt9j60GCbarzMzdf1VHFpOxfQh/ez7wyadLMqkg==
"@rollup/plugin-node-resolve@^11.2.1":
version "11.2.1"
resolved "https://registry.yarnpkg.com/@rollup/plugin-node-resolve/-/plugin-node-resolve-11.2.1.tgz#82aa59397a29cd4e13248b106e6a4a1880362a60"
integrity sha512-yc2n43jcqVyGE2sqV5/YCmocy9ArjVAP/BeXyTtADTBBX6V0e5UMqwO8CdQ0kzjb6zu5P1qMzsScCMRvE9OlVg==
dependencies:
"@rollup/pluginutils" "^3.1.0"
"@types/resolve" "1.17.1"
builtin-modules "^3.1.0"
deepmerge "^4.2.2"
is-module "^1.0.0"
resolve "^1.17.0"
resolve "^1.19.0"

"@rollup/plugin-replace@^2.4.1":
version "2.4.1"
Expand Down Expand Up @@ -11412,7 +11412,7 @@ resolve@1.1.7:
resolved "https://registry.yarnpkg.com/resolve/-/resolve-1.1.7.tgz#203114d82ad2c5ed9e8e0411b3932875e889e97b"
integrity sha1-IDEU2CrSxe2ejgQRs5ModeiJ6Xs=

resolve@^1.1.6, resolve@^1.14.2:
resolve@^1.1.6, resolve@^1.14.2, resolve@^1.19.0:
version "1.22.1"
resolved "https://registry.yarnpkg.com/resolve/-/resolve-1.22.1.tgz#27cb2ebb53f91abb49470a928bba7558066ac177"
integrity sha512-nBpuuYuY5jFsli/JIs1oldw6fOQCBioohqWZg/2hiaOybXOft4lonv85uDOKXdf8rhyK159cxU5cDcK/NKk8zw==
Expand Down

0 comments on commit 76f0163

Please sign in to comment.