Skip to content

Commit 2a4d3dd

Browse files
feat: show warning for npm modules with extraneous files (#6069)
* feat: show warning for npm modules with extraneous files * refactor: add feature flag
1 parent 06e302b commit 2a4d3dd

File tree

3 files changed

+17
-21
lines changed

3 files changed

+17
-21
lines changed

src/lib/edge-functions/consts.mjs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,6 @@ export const PUBLIC_URL_PATH = '.netlify/internal/edge-functions'
88
// Netlify Build.
99
export const featureFlags = {
1010
edge_functions_config_export: true,
11+
edge_functions_npm_modules: true,
1112
edge_functions_read_deno_config: true,
1213
}

src/lib/edge-functions/proxy.mjs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import * as bundler from '@netlify/edge-bundler'
88
import getAvailablePort from 'get-port'
99

1010
import { NETLIFYDEVERR, NETLIFYDEVWARN, chalk, error as printError, log } from '../../utils/command-helpers.mjs'
11-
import { isFeatureFlagEnabled } from '../../utils/feature-flags.mjs'
1211
import { getGeoLocation } from '../geo-location.mjs'
1312
import { getPathInProject } from '../settings.mjs'
1413
import { startSpinner, stopSpinner } from '../spinner.mjs'
@@ -110,7 +109,7 @@ export const initializeProxy = async ({
110109
const userFunctionsPath = config.build.edge_functions
111110
const isolatePort = await getAvailablePort()
112111
const buildFeatureFlags = {
113-
edge_functions_npm_modules: isFeatureFlagEnabled('edge_functions_npm_modules', siteInfo),
112+
edge_functions_npm_modules: true,
114113
}
115114
const runtimeFeatureFlags = ['edge_functions_bootstrap_failure_mode']
116115

src/lib/edge-functions/registry.mjs

Lines changed: 15 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,6 @@ export class EdgeFunctionsRegistry {
4040
/** @type {RunIsolate} */
4141
#runIsolate
4242

43-
/** @type {boolean} */
44-
#hasShownNPMWarning = false
45-
4643
/** @type {Error | null} */
4744
#buildError = null
4845

@@ -167,22 +164,13 @@ export class EdgeFunctionsRegistry {
167164
*/
168165
async #build() {
169166
try {
170-
const {
171-
features = {},
172-
functionsConfig,
173-
graph,
174-
success,
175-
} = await this.#runIsolate(this.#functions, this.#env, {
176-
getFunctionsConfig: true,
177-
})
178-
179-
if (features.npmModules && !this.#hasShownNPMWarning) {
180-
log(
181-
`${NETLIFYDEVWARN} Support for npm modules in edge functions is an experimental feature. To learn more about the current state of this capability or to report a problem, refer to https://ntl.fyi/edge-functions-npm.`,
182-
)
183-
184-
this.#hasShownNPMWarning = true
185-
}
167+
const { functionsConfig, graph, npmSpecifiersWithExtraneousFiles, success } = await this.#runIsolate(
168+
this.#functions,
169+
this.#env,
170+
{
171+
getFunctionsConfig: true,
172+
},
173+
)
186174

187175
if (!success) {
188176
throw new Error('Build error')
@@ -207,6 +195,14 @@ export class EdgeFunctionsRegistry {
207195
)
208196

209197
this.#processGraph(graph)
198+
199+
if (npmSpecifiersWithExtraneousFiles.length !== 0) {
200+
const modules = npmSpecifiersWithExtraneousFiles.map((name) => chalk.yellow(name)).join(', ')
201+
202+
log(
203+
`${NETLIFYDEVWARN} The following npm modules, which are directly or indirectly imported by an edge function, may not be supported: ${modules}. For more information, visit https://ntl.fyi/edge-npm.`,
204+
)
205+
}
210206
} catch (error) {
211207
this.#buildError = error
212208

0 commit comments

Comments
 (0)