Skip to content

Commit e2aebc3

Browse files
committedOct 18, 2023
Also make astro, gatsby, next and remix entry patterns overridable
1 parent 47b09c9 commit e2aebc3

File tree

5 files changed

+25
-10
lines changed

5 files changed

+25
-10
lines changed
 

‎src/plugins/astro/index.ts

+6-2
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,10 @@ export const ENTRY_FILE_PATTERNS = ['astro.config.{js,cjs,mjs,ts}', 'src/content
1717
/** @public */
1818
export const PRODUCTION_ENTRY_FILE_PATTERNS = ['src/pages/**/*.{astro,mdx,js,ts}', 'src/content/**/*.mdx'];
1919

20-
export const findDependencies: GenericPluginCallback = async () => {
21-
return [...ENTRY_FILE_PATTERNS.map(toEntryPattern), ...PRODUCTION_ENTRY_FILE_PATTERNS.map(toProductionEntryPattern)];
20+
export const findDependencies: GenericPluginCallback = async (configFilePath, options) => {
21+
const { config } = options;
22+
23+
return config.entry
24+
? config.entry.map(toProductionEntryPattern)
25+
: [...ENTRY_FILE_PATTERNS.map(toEntryPattern), ...PRODUCTION_ENTRY_FILE_PATTERNS.map(toProductionEntryPattern)];
2226
};

‎src/plugins/gatsby/index.ts

+4-2
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,12 @@ export const PRODUCTION_ENTRY_FILE_PATTERNS = [
2626
'plugins/**/gatsby-{browser,ssr}.{js,jsx,ts,tsx}',
2727
];
2828

29-
const findGatsbyDependencies: GenericPluginCallback = async (configFilePath, { isProduction }) => {
29+
const findGatsbyDependencies: GenericPluginCallback = async (configFilePath, options) => {
30+
const { isProduction, config } = options;
31+
3032
const localConfig: GatsbyConfig | GatsbyNode | undefined = await load(configFilePath);
3133

32-
const entryPatterns = PRODUCTION_ENTRY_FILE_PATTERNS.map(toProductionEntryPattern);
34+
const entryPatterns = (config.entry ?? PRODUCTION_ENTRY_FILE_PATTERNS).map(toProductionEntryPattern);
3335

3436
if (isProduction || !localConfig) return entryPatterns;
3537

‎src/plugins/next/index.ts

+6-2
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,10 @@ export const PRODUCTION_ENTRY_FILE_PATTERNS = [
3131
...productionEntryFilePatternsWithoutSrc.map(pattern => `src/${pattern}`),
3232
];
3333

34-
export const findDependencies: GenericPluginCallback = async () => {
35-
return [...ENTRY_FILE_PATTERNS.map(toEntryPattern), ...PRODUCTION_ENTRY_FILE_PATTERNS.map(toProductionEntryPattern)];
34+
export const findDependencies: GenericPluginCallback = async (configFilePath, options) => {
35+
const { config } = options;
36+
37+
return config.entry
38+
? config.entry.map(toProductionEntryPattern)
39+
: [...ENTRY_FILE_PATTERNS.map(toEntryPattern), ...PRODUCTION_ENTRY_FILE_PATTERNS.map(toProductionEntryPattern)];
3640
};

‎src/plugins/remix/index.ts

+6-2
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,12 @@ export const PRODUCTION_ENTRY_FILE_PATTERNS = [
2323
'server.{js,ts}',
2424
];
2525

26-
const findRemixDependencies: GenericPluginCallback = async () => {
27-
return [...ENTRY_FILE_PATTERNS.map(toEntryPattern), ...PRODUCTION_ENTRY_FILE_PATTERNS.map(toProductionEntryPattern)];
26+
const findRemixDependencies: GenericPluginCallback = async (configFilePath, options) => {
27+
const { config } = options;
28+
29+
return config.entry
30+
? config.entry.map(toProductionEntryPattern)
31+
: [...ENTRY_FILE_PATTERNS.map(toEntryPattern), ...PRODUCTION_ENTRY_FILE_PATTERNS.map(toProductionEntryPattern)];
2832
};
2933

3034
export const findDependencies = timerify(findRemixDependencies);

‎test/plugins/gatsby.test.ts

+3-2
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,13 @@ import assert from 'node:assert/strict';
22
import test from 'node:test';
33
import * as gatsby from '../../src/plugins/gatsby/index.js';
44
import { resolve, join } from '../../src/util/path.js';
5+
import { pluginConfig as config } from '../helpers/index.js';
56

67
const cwd = resolve('fixtures/plugins/gatsby');
78

89
test('Find dependencies in Gatsby configuration (gatsby-config.js)', async () => {
910
const configFilePath = join(cwd, 'gatsby-config.js');
10-
const dependencies = await gatsby.findDependencies(configFilePath, {});
11+
const dependencies = await gatsby.findDependencies(configFilePath, { config });
1112
assert.deepEqual(dependencies, [
1213
'@sentry/gatsby',
1314
'gatsby-plugin-webpack-bundle-analyser-v2',
@@ -25,7 +26,7 @@ test('Find dependencies in Gatsby configuration (gatsby-config.js)', async () =>
2526

2627
test('Find dependencies in Gatsby configuration (gatsby-node.js)', async () => {
2728
const configFilePath = join(cwd, 'gatsby-node.js');
28-
const dependencies = await gatsby.findDependencies(configFilePath, {});
29+
const dependencies = await gatsby.findDependencies(configFilePath, { config });
2930
assert.deepEqual(dependencies, [
3031
'@babel/plugin-proposal-function-bind',
3132
'@babel/plugin-proposal-export-default-from',

0 commit comments

Comments
 (0)
Please sign in to comment.