Skip to content

Commit

Permalink
Bundle packages that could not be resolved at build time
Browse files Browse the repository at this point in the history
Update webpack externals configuration, so that we fallback to webpack to handle the dependency in case its absolute path could not be resolved using the node.js resolver at build time (as opposed to assuming that the dependency may be available later at runtime). This also ensures a failing build in case the requested module is missing, which in turn prevents bad deployments using "defective" build artifacts.

This specifically fixes a scenario where the requested package is a local workspace that requires some build transforms, as it is consumed directly from sources (e.g., a local workspace authored in TypeScript).
  • Loading branch information
shYkiSto authored and fusionjs-sync-bot[bot] committed Aug 12, 2022
1 parent f938b14 commit 2dc14e3
Show file tree
Hide file tree
Showing 17 changed files with 37 additions and 11 deletions.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions fusion-cli-tests/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@
"eventsource": "^2.0.1",
"fixture-es2017-pkg": "0.0.0-monorepo",
"fixture-macro-pkg": "0.0.0-monorepo",
"fixture-pkg": "0.0.0-monorepo",
"fixture-pure-esm-pkg": "0.0.0-monorepo",
"fixture-typescript-local-pkg": "0.0.0-monorepo",
"flow-bin": "^0.131.0",
"fusion-core": "0.0.0-monorepo",
"fusion-plugin-apollo": "0.0.0-monorepo",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
!node_modules
.fusion_babel_cache/

This file was deleted.

8 changes: 7 additions & 1 deletion fusion-cli-tests/test/e2e/typescript/fixture/src/root.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
import React from 'react';
import test from 'fixture-typescript-local-pkg/test';

const TITLE: string = 'TypeScript';

export default <h1>{TITLE}</h1>;
export default (
<>
<h1>{TITLE}</h1>
<h2>{test}</h2>
</>
);
2 changes: 2 additions & 0 deletions fusion-cli-tests/test/e2e/typescript/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ describe('TypeScript app', () => {
await page.goto(`http://localhost:${port}/`, {waitUntil: 'load'});
const content = await page.content();
t.ok(content.includes('TypeScript'));
t.ok(content.includes('FIXTURE_TYPESCRIPT_LOCAL_PACKAGE_CONTENT'));

browser.close();
proc.kill('SIGKILL');
Expand All @@ -45,6 +46,7 @@ describe('TypeScript app', () => {
await page.goto(`${url}/`, {waitUntil: 'load'});
const content = await page.content();
t.ok(content.includes('TypeScript'));
t.ok(content.includes('FIXTURE_TYPESCRIPT_LOCAL_PACKAGE_CONTENT'));

await app.teardown();
}, 15000);
Expand Down
15 changes: 11 additions & 4 deletions fusion-cli/build/get-webpack-config.js
Original file line number Diff line number Diff line change
Expand Up @@ -641,10 +641,14 @@ function getWebpackConfig(opts /*: WebpackConfigOpts */) {

if (/^[@a-z\-0-9]+/.test(request)) {
const absolutePath = getModuleAbsolutePath(context, request);
// do not bundle external packages and those not whitelisted
if (typeof absolutePath !== 'string') {
// if module is missing, skip rewriting to absolute path
return handleExternalResult(request);
if (!absolutePath) {
// bundle the dependency if absolute path could not be determined
// using node.js resolver at build time. This will ensure a build
// failure in case the dependency is missing, as opposed to making
// an assumption that the dependency will be available at runtime.
// And will also fallback to webpack for resolving, and building a
// module imported from a local workspace (monorepo support).
return handleExternalResult();
}

if (experimentalBundleTest) {
Expand All @@ -664,8 +668,11 @@ function getWebpackConfig(opts /*: WebpackConfigOpts */) {
);
}
}

// do not bundle external packages
return handleExternalModule(absolutePath);
}

// bundle everything else (local files, __*)
return handleExternalResult();
}
Expand Down

0 comments on commit 2dc14e3

Please sign in to comment.