Skip to content

Commit

Permalink
update externalesm support (#1668)
Browse files Browse the repository at this point in the history
  • Loading branch information
FredKSchott authored Nov 26, 2020
1 parent 5b7ce4d commit 3fbf1a2
Show file tree
Hide file tree
Showing 8 changed files with 40 additions and 11 deletions.
11 changes: 7 additions & 4 deletions esinstall/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,7 @@ interface InstallOptions {
polyfillNode: boolean;
sourceMap?: boolean | 'inline';
externalPackage: string[];
externalPackageEsm: string[];
packageLookupFields: string[];
namedExports: string[];
rollup: {
Expand All @@ -253,6 +254,7 @@ function setOptionDefaults(_options: PublicInstallOptions): InstallOptions {
logger: console,
dest: 'web_modules',
externalPackage: [],
externalPackageEsm: [],
polyfillNode: false,
packageLookupFields: [],
env: {},
Expand All @@ -278,7 +280,8 @@ export async function install(
logger,
dest: destLoc,
namedExports,
externalPackage: externalPackages,
externalPackage,
externalPackageEsm,
sourceMap,
env: userEnv,
rollup: userDefinedRollup,
Expand All @@ -295,7 +298,7 @@ export async function install(
installTargets
.filter(
(dep) =>
!externalPackages.some((packageName) => isImportOfPackage(dep.specifier, packageName)),
!externalPackage.some((packageName) => isImportOfPackage(dep.specifier, packageName)),
)
.map((dep) => dep.specifier)
.map((specifier) => {
Expand Down Expand Up @@ -360,7 +363,7 @@ ${colors.dim(
const inputOptions: InputOptions = {
input: installEntrypoints,
context: userDefinedRollup.context,
external: (id) => externalPackages.some((packageName) => isImportOfPackage(id, packageName)),
external: (id) => externalPackage.some((packageName) => isImportOfPackage(id, packageName)),
treeshake: {moduleSideEffects: 'no-external'},
plugins: [
rollupPluginAlias({
Expand Down Expand Up @@ -389,7 +392,7 @@ ${colors.dim(
rollupPluginReplace(generateEnvReplacements(env)),
rollupPluginCommonjs({
extensions: ['.js', '.cjs'],
externalEsm: process.env.EXTERNAL_ESM_PACKAGES || [],
esmExternals: externalPackageEsm,
requireReturnsDefault: 'auto',
} as RollupCommonJSOptions),
rollupPluginWrapInstallTargets(!!isTreeshake, autoDetectNamedExports, installTargets, logger),
Expand Down
16 changes: 10 additions & 6 deletions test/esinstall/config-external/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,23 @@
"snowpack": {
"installOptions": {
"externalPackage": [
"config-external-pkg-b",
"config-external-pkg-c"
],
"externalPackageEsm": [
"config-external-pkg-b"
]
},
"install": [
"config-external-pkg-a"
],
"buildOptions": {
"minify": false
}
"config-external-pkg-a",
"config-external-pkg-cjs"
]
},
"dependencies": {
"config-external-pkg-a": "file:./packages/config-external-pkg-a",
"config-external-pkg-b": "file:./packages/config-external-pkg-b"
"config-external-pkg-b": "file:./packages/config-external-pkg-b",
"config-external-pkg-c": "file:./packages/config-external-pkg-c",
"config-external-pkg-cjs": "file:./packages/config-external-pkg-cjs"
},
"devDependencies": {
"snowpack": "^2.14.3"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import {foo} from 'config-external-pkg-b';
import {foo as foo_} from 'config-external-pkg-b/entrypoint';
console.log(foo, foo_);
import bar from 'config-external-pkg-c';
console.log(foo, foo_, bar);
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
module.exports = {foo: 42};
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@

{
"name": "config-external-pkg-c",
"version": "1.2.3",
"module": "entrypoint.js"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
const foo = require('config-external-pkg-b');
const _foo = require('config-external-pkg-c');
console.log(foo, _foo);
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"name": "config-external-pkg-cjs",
"version": "1.2.3",
"main": "entrypoint.js"
}
6 changes: 6 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -5280,6 +5280,12 @@ config-chain@^1.1.11, config-chain@^1.1.12:
"config-external-pkg-b@file:./test/esinstall/config-external/packages/config-external-pkg-b":
version "1.2.3"

"config-external-pkg-c@file:./test/esinstall/config-external/packages/config-external-pkg-c":
version "1.2.3"

"config-external-pkg-cjs@file:./test/esinstall/config-external/packages/config-external-pkg-cjs":
version "1.2.3"

connect-history-api-fallback@^1:
version "1.6.0"
resolved "https://registry.yarnpkg.com/connect-history-api-fallback/-/connect-history-api-fallback-1.6.0.tgz#8b32089359308d111115d81cad3fceab888f97bc"
Expand Down

0 comments on commit 3fbf1a2

Please sign in to comment.