Skip to content

Commit

Permalink
Also make astro, gatsby, next and remix entry patterns overridable
Browse files Browse the repository at this point in the history
  • Loading branch information
webpro committed Oct 18, 2023
1 parent 47b09c9 commit e2aebc3
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 10 deletions.
8 changes: 6 additions & 2 deletions src/plugins/astro/index.ts
Expand Up @@ -17,6 +17,10 @@ export const ENTRY_FILE_PATTERNS = ['astro.config.{js,cjs,mjs,ts}', 'src/content
/** @public */
export const PRODUCTION_ENTRY_FILE_PATTERNS = ['src/pages/**/*.{astro,mdx,js,ts}', 'src/content/**/*.mdx'];

export const findDependencies: GenericPluginCallback = async () => {
return [...ENTRY_FILE_PATTERNS.map(toEntryPattern), ...PRODUCTION_ENTRY_FILE_PATTERNS.map(toProductionEntryPattern)];
export const findDependencies: GenericPluginCallback = async (configFilePath, options) => {
const { config } = options;

return config.entry
? config.entry.map(toProductionEntryPattern)
: [...ENTRY_FILE_PATTERNS.map(toEntryPattern), ...PRODUCTION_ENTRY_FILE_PATTERNS.map(toProductionEntryPattern)];
};
6 changes: 4 additions & 2 deletions src/plugins/gatsby/index.ts
Expand Up @@ -26,10 +26,12 @@ export const PRODUCTION_ENTRY_FILE_PATTERNS = [
'plugins/**/gatsby-{browser,ssr}.{js,jsx,ts,tsx}',
];

const findGatsbyDependencies: GenericPluginCallback = async (configFilePath, { isProduction }) => {
const findGatsbyDependencies: GenericPluginCallback = async (configFilePath, options) => {
const { isProduction, config } = options;

const localConfig: GatsbyConfig | GatsbyNode | undefined = await load(configFilePath);

const entryPatterns = PRODUCTION_ENTRY_FILE_PATTERNS.map(toProductionEntryPattern);
const entryPatterns = (config.entry ?? PRODUCTION_ENTRY_FILE_PATTERNS).map(toProductionEntryPattern);

if (isProduction || !localConfig) return entryPatterns;

Expand Down
8 changes: 6 additions & 2 deletions src/plugins/next/index.ts
Expand Up @@ -31,6 +31,10 @@ export const PRODUCTION_ENTRY_FILE_PATTERNS = [
...productionEntryFilePatternsWithoutSrc.map(pattern => `src/${pattern}`),
];

export const findDependencies: GenericPluginCallback = async () => {
return [...ENTRY_FILE_PATTERNS.map(toEntryPattern), ...PRODUCTION_ENTRY_FILE_PATTERNS.map(toProductionEntryPattern)];
export const findDependencies: GenericPluginCallback = async (configFilePath, options) => {
const { config } = options;

return config.entry
? config.entry.map(toProductionEntryPattern)
: [...ENTRY_FILE_PATTERNS.map(toEntryPattern), ...PRODUCTION_ENTRY_FILE_PATTERNS.map(toProductionEntryPattern)];
};
8 changes: 6 additions & 2 deletions src/plugins/remix/index.ts
Expand Up @@ -23,8 +23,12 @@ export const PRODUCTION_ENTRY_FILE_PATTERNS = [
'server.{js,ts}',
];

const findRemixDependencies: GenericPluginCallback = async () => {
return [...ENTRY_FILE_PATTERNS.map(toEntryPattern), ...PRODUCTION_ENTRY_FILE_PATTERNS.map(toProductionEntryPattern)];
const findRemixDependencies: GenericPluginCallback = async (configFilePath, options) => {
const { config } = options;

return config.entry
? config.entry.map(toProductionEntryPattern)
: [...ENTRY_FILE_PATTERNS.map(toEntryPattern), ...PRODUCTION_ENTRY_FILE_PATTERNS.map(toProductionEntryPattern)];
};

export const findDependencies = timerify(findRemixDependencies);
5 changes: 3 additions & 2 deletions test/plugins/gatsby.test.ts
Expand Up @@ -2,12 +2,13 @@ import assert from 'node:assert/strict';
import test from 'node:test';
import * as gatsby from '../../src/plugins/gatsby/index.js';
import { resolve, join } from '../../src/util/path.js';
import { pluginConfig as config } from '../helpers/index.js';

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

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

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

0 comments on commit e2aebc3

Please sign in to comment.