Skip to content

Commit

Permalink
fix: Externalize built-ins and dependencies.
Browse files Browse the repository at this point in the history
  • Loading branch information
darkobits committed Jul 10, 2023
1 parent d6741cc commit bd43a05
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 7 deletions.
12 changes: 12 additions & 0 deletions package-lock.json

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

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
"node-version": "^3.0.0",
"read-pkg-up": "^10.0.0",
"rollup": "^3.26.2",
"rollup-plugin-node-externals": "^6.1.1",
"tsconfck": "^2.1.1",
"yargs": "^17.7.2"
},
Expand Down
18 changes: 14 additions & 4 deletions src/lib/configuration/strategies/rollup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {
type InputOptions,
type OutputOptions
} from 'rollup';
import { nodeExternals } from 'rollup-plugin-node-externals';
import * as tsConfck from 'tsconfck';

import log from 'lib/log';
Expand Down Expand Up @@ -78,8 +79,7 @@ export async function rollupStrategy<M = any>(filePath: string, pkgInfo: Package

log.verbose(prefix, `Using format: ${log.chalk.bold(format)}`);

// const tempFileName = `.${parsedFilePath.name}.${Date.now()}${outExt}`;
const tempFileName = `.${parsedFilePath.name}.temp${outExt}`;
const tempFileName = `.${parsedFilePath.name}.${Date.now()}${outExt}`;
const tempFilePath = path.join(path.dirname(filePath), tempFileName);

log.verbose(prefix, `Temporary file path: ${log.chalk.green(tempFilePath)}`);
Expand All @@ -89,7 +89,16 @@ export async function rollupStrategy<M = any>(filePath: string, pkgInfo: Package

const inputOptions: InputOptions = {
input: filePath,
plugins: []
plugins: [
nodeExternals({
builtinsPrefix: 'ignore',
packagePath: path.resolve(pkgInfo.root, 'package.json'),
deps: true,
devDeps: true,
peerDeps: true,
optDeps: true
})
]
};

// If the user has a TypeScript configuration file, enable TypeScript
Expand All @@ -100,7 +109,8 @@ export async function rollupStrategy<M = any>(filePath: string, pkgInfo: Package
log.verbose(prefix, 'Using TypeScript configuration:', log.chalk.green(tsConfigFilePath));
// Add TypeScript config to inputOptions here.
inputOptions.plugins?.push(typescriptPlugin({
sourceMap: false
sourceMap: false,
outputToFilesystem: false
}));
}

Expand Down
9 changes: 6 additions & 3 deletions tests/fixtures/esm/ts-extension/app.config.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
// This is here to test that Rollup handles externals properly.
import path from 'path';

// This file should get transpiled to ESM because we have type: module in
// package.json.
// eslint-disable-next-line import/no-unresolved
Expand All @@ -6,9 +9,9 @@ import { testFn } from 'lib/utils';
// This tests that we can resolve paths to other files that themselves require
// a compilation step. Specifically, the Rollup strategy should be used, and
// the imported values should be inlined into the final config file.
if (!testFn()) {
throw new Error('testFn failed');
}
if (!testFn()) throw new Error('testFn failed');

void path;

export default {
foo: 'bar'
Expand Down

0 comments on commit bd43a05

Please sign in to comment.