Skip to content

Commit

Permalink
node module invalidations passed in through cli
Browse files Browse the repository at this point in the history
  • Loading branch information
gorakong committed Dec 5, 2023
1 parent b530d34 commit 2c1fdc0
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 3 deletions.
3 changes: 3 additions & 0 deletions packages/core/core/src/RequestTracker.js
Original file line number Diff line number Diff line change
Expand Up @@ -1219,6 +1219,9 @@ async function loadRequestGraph(options): Async<RequestGraph> {
snapshotPath,
opts,
);
if (options.nodeModuleInvalidations != null) {
events.push(...options.nodeModuleInvalidations);
}
requestGraph.invalidateUnpredictableNodes();
requestGraph.invalidateOnBuildNodes();
requestGraph.invalidateEnvNodes(options.env);
Expand Down
8 changes: 8 additions & 0 deletions packages/core/core/src/resolveOptions.js
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,13 @@ export default async function resolveOptions(

let port = determinePort(initialOptions.serveOptions, env.PORT);

let nodeModuleInvalidations = initialOptions.nodeModuleInvalidations?.map(
path => ({
type: 'create',
path,
}),
);

return {
config: getRelativeConfigSpecifier(
inputFS,
Expand All @@ -166,6 +173,7 @@ export default async function resolveOptions(
shouldBuildLazily,
lazyIncludes,
lazyExcludes,
nodeModuleInvalidations,
shouldBundleIncrementally: initialOptions.shouldBundleIncrementally ?? true,
shouldContentHash,
serveOptions: initialOptions.serveOptions
Expand Down
5 changes: 5 additions & 0 deletions packages/core/core/src/types.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import type {FileSystem} from '@parcel/fs';
import type {Cache} from '@parcel/cache';
import type {PackageManager} from '@parcel/package-manager';
import type {ProjectPath} from './projectPath';
import type {EventType} from '@parcel/watcher';

export type ParcelPluginNode = {|
packageName: PackageName,
Expand Down Expand Up @@ -280,6 +281,10 @@ export type ParcelOptions = {|
shouldTrace: boolean,
shouldPatchConsole: boolean,
detailedReport?: ?DetailedReportOptions,
nodeModuleInvalidations?: Array<{|
path: FilePath,
type: EventType,
|}>,

inputFS: FileSystem,
outputFS: FileSystem,
Expand Down
14 changes: 11 additions & 3 deletions packages/core/parcel/src/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,9 @@ const commonOptions = {
},
[],
],
'--node-module-invalidations <path>': [
'Comma separated list of file paths of node_module packages to be invalidated',
],
};

var hmrOptions = {
Expand Down Expand Up @@ -213,6 +216,7 @@ if (!args[2] || !program.commands.some(c => c.name() === args[2])) {
program.parse(args);

function runCommand(...args) {
console.log('hello run1');
run(...args).catch(handleUncaughtException);
}

Expand Down Expand Up @@ -466,10 +470,11 @@ async function normalizeOptions(

let mode = command.name() === 'build' ? 'production' : 'development';

const normalizeIncludeExcludeList = (input?: string): string[] => {
const normalizeCommaSeparatedList = (input?: string): string[] => {
if (typeof input !== 'string') return [];
return input.split(',').map(value => value.trim());
};

return {
shouldDisableCache: command.cache === false,
cacheDir: command.cacheDir,
Expand All @@ -484,8 +489,11 @@ async function normalizeOptions(
shouldProfile: command.profile,
shouldTrace: command.trace,
shouldBuildLazily: typeof command.lazy !== 'undefined',
lazyIncludes: normalizeIncludeExcludeList(command.lazy),
lazyExcludes: normalizeIncludeExcludeList(command.lazyExclude),
lazyIncludes: normalizeCommaSeparatedList(command.lazy),
lazyExcludes: normalizeCommaSeparatedList(command.lazyExclude),
nodeModuleInvalidations: normalizeCommaSeparatedList(
command.nodeModuleInvalidations,
),
shouldBundleIncrementally:
process.env.PARCEL_INCREMENTAL_BUNDLING === 'false' ? false : true,
detailedReport:
Expand Down
1 change: 1 addition & 0 deletions packages/core/types/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -306,6 +306,7 @@ export type InitialParcelOptions = {|
+lazyIncludes?: string[],
+lazyExcludes?: string[],
+shouldBundleIncrementally?: boolean,
+nodeModuleInvalidations?: Array<FilePath>,

+inputFS?: FileSystem,
+outputFS?: FileSystem,
Expand Down

0 comments on commit 2c1fdc0

Please sign in to comment.