@@ -10,7 +10,7 @@ const {
1010} = primordials ;
1111
1212const assert = require ( 'internal/assert' ) ;
13- const { getLazy } = require ( 'internal/util' ) ;
13+ const { emitExperimentalWarning , getLazy } = require ( 'internal/util' ) ;
1414const { resolve : pathResolve , dirname } = require ( 'path' ) ;
1515const { fileURLToPath } = require ( 'internal/url' ) ;
1616
@@ -30,7 +30,6 @@ const PROTOCOL_REGEXP = /^[a-zA-Z][a-zA-Z0-9+\-.]*:\/\//;
3030// Singleton - initialized once on first call
3131let packageMap ;
3232let packageMapPath ;
33- let emittedWarning = false ;
3433
3534/**
3635 * @typedef {object } PackageMapEntry
@@ -208,7 +207,7 @@ function parsePackageName(specifier) {
208207function loadPackageMap ( configPath ) {
209208 let content ;
210209 try {
211- content = fs . readFileSync ( configPath , 'utf8' ) ;
210+ content = fs . readFileSync ( configPath ) ;
212211 } catch ( err ) {
213212 if ( err . code === 'ENOENT' ) {
214213 throw new ERR_PACKAGE_MAP_INVALID ( configPath , 'file not found' ) ;
@@ -226,19 +225,6 @@ function loadPackageMap(configPath) {
226225 return new PackageMap ( configPath , data ) ;
227226}
228227
229- /**
230- * Emit experimental warning on first use.
231- */
232- function emitExperimentalWarning ( ) {
233- if ( ! emittedWarning ) {
234- emittedWarning = true ;
235- process . emitWarning (
236- 'Package map resolution is an experimental feature and might change at any time' ,
237- 'ExperimentalWarning' ,
238- ) ;
239- }
240- }
241-
242228/**
243229 * Get the singleton package map, initializing on first call.
244230 * @returns {PackageMap|null }
@@ -252,8 +238,15 @@ function getPackageMap() {
252238 return null ;
253239 }
254240
255- emitExperimentalWarning ( ) ;
256- packageMap = loadPackageMap ( pathResolve ( packageMapPath ) ) ;
241+ emitExperimentalWarning ( 'Package maps' ) ;
242+
243+ try {
244+ packageMap = loadPackageMap ( pathResolve ( packageMapPath ) ) ;
245+ } catch ( err ) {
246+ packageMap = new PackageMap ( packageMapPath , { packages : { } } ) ;
247+ throw err ;
248+ }
249+
257250 return packageMap ;
258251}
259252
@@ -262,7 +255,7 @@ function getPackageMap() {
262255 * @returns {boolean }
263256 */
264257function hasPackageMap ( ) {
265- return getPackageMap ( ) !== null ;
258+ return ! ! getPackageMapPath ( ) ;
266259}
267260
268261/**
0 commit comments