Skip to content

Commit 80de145

Browse files
committed
Clean up and refactor some constants
1 parent 2afbd66 commit 80de145

File tree

2 files changed

+14
-11
lines changed

2 files changed

+14
-11
lines changed

packages/pwa-kit-extension-sdk/src/configs/webpack/overrides-resolver-loader.ts

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import path from 'path'
1111
import resolve from 'resolve'
1212

1313
// Local Imports
14-
import {buildCandidatePaths, getPackageName} from '../../shared/utils'
14+
import {buildCandidatePaths, getPackageName, SETUP_FILE_REGEX} from '../../shared/utils'
1515

1616
// Types
1717
import type {ExtendedCompiler} from './types'
@@ -23,6 +23,12 @@ const OVERRIDABLE_FILE_NAME = '.force_overrides'
2323
const REQUIRES_REGEX = /require\(['"](\..*?)['"]\)/g
2424
const SRC = 'src'
2525

26+
// Cache for processed overrides
27+
const OVERRIDABLE_CACHE = {
28+
node: [] as string[],
29+
web: [] as string[]
30+
}
31+
2632
/**
2733
* Webpack loader to override the resolution of a module based on the PWA-Kit applications
2834
* extension configuration.
@@ -118,11 +124,6 @@ const OverrideResolverLoader = function (this: LoaderContext<any>) {
118124
})
119125
}
120126

121-
const OVERRIDABLE_CACHE = {
122-
node: [] as string[],
123-
web: [] as string[]
124-
}
125-
126127
/**
127128
*
128129
* @param {*} source
@@ -133,13 +134,14 @@ const validateOverrideSource = (source: string, options: any = {}) => {
133134
const {target = 'node', overridables = []} = options
134135
const isMonoRepo = true
135136
const isExtensionFile = source.includes(`${path.sep}${EXTENSION_PACKAGE_PREFIX}`)
137+
const isSetupFile = SETUP_FILE_REGEX.test(source)
136138
const targetCache = OVERRIDABLE_CACHE[target as keyof typeof OVERRIDABLE_CACHE]
137139

138140
// Exit early if we have:
139141
// 1. Processed this file already.
140142
// 2. The file is not an extension file.
141-
// 3. TBD - The file is in the disallowed list.
142-
if (targetCache.includes(source) || !isExtensionFile) {
143+
// 3. The file is an extension setup file.
144+
if (targetCache.includes(source) || !isExtensionFile || isSetupFile) {
143145
return false
144146
}
145147

packages/pwa-kit-extension-sdk/src/shared/utils/extensibility.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,10 @@ import {
2020
import {expand} from './index'
2121

2222
// CONSTANTS
23-
// const REACT_EXTENSIBILITY_FILE = 'setup-app'
24-
// const EXPRESS_EXTENSIBILITY_FILE = 'setup-server'
25-
// const SUPPORTED_FILE_TYPES = ['.ts', '.js']
23+
export const REACT_SETUP_FILE = 'setup-app'
24+
export const EXPRESS_SETUP_FILE = 'setup-server'
25+
export const SUPPORTED_FILE_TYPES = ['ts', 'js', 'tsx', 'jsx']
26+
export const SETUP_FILE_REGEX = new RegExp(`(${REACT_SETUP_FILE}|${EXPRESS_SETUP_FILE})\.(${SUPPORTED_FILE_TYPES.join('|')})$`, 'i')
2627

2728
// TODO: Update this block comment.
2829
/**

0 commit comments

Comments
 (0)