@jsenv/core 32.0.0 → 32.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/main.js CHANGED
@@ -1,7 +1,7 @@
1
1
  import { pathToFileURL, fileURLToPath } from "node:url";
2
2
  import { chmod, stat, lstat, readdir, promises, unlink, openSync, closeSync, rmdir, readFile as readFile$1, readFileSync as readFileSync$1, watch, readdirSync, statSync, writeFile as writeFile$1, writeFileSync as writeFileSync$1, mkdirSync, createReadStream, existsSync, realpathSync } from "node:fs";
3
3
  import crypto, { createHash } from "node:crypto";
4
- import { dirname, extname, basename } from "node:path";
4
+ import { dirname, extname } from "node:path";
5
5
  import { URL_META, filterV8Coverage } from "./js/v8_coverage.js";
6
6
  import process$1, { memoryUsage } from "node:process";
7
7
  import os, { networkInterfaces } from "node:os";
@@ -6965,6 +6965,38 @@ const generateAccessControlHeaders = ({
6965
6965
  };
6966
6966
  };
6967
6967
 
6968
+ const lookupPackageDirectory = currentUrl => {
6969
+ if (currentUrl === "file:///") {
6970
+ return null;
6971
+ }
6972
+ const packageJsonFileUrl = `${currentUrl}package.json`;
6973
+ if (existsSync(new URL(packageJsonFileUrl))) {
6974
+ return currentUrl;
6975
+ }
6976
+ return lookupPackageDirectory(getParentUrl$1(currentUrl));
6977
+ };
6978
+ const getParentUrl$1 = url => {
6979
+ if (url.startsWith("file://")) {
6980
+ // With node.js new URL('../', 'file:///C:/').href
6981
+ // returns "file:///C:/" instead of "file:///"
6982
+ const resource = url.slice("file://".length);
6983
+ const slashLastIndex = resource.lastIndexOf("/");
6984
+ if (slashLastIndex === -1) {
6985
+ return url;
6986
+ }
6987
+ const lastCharIndex = resource.length - 1;
6988
+ if (slashLastIndex === lastCharIndex) {
6989
+ const slashBeforeLastIndex = resource.lastIndexOf("/", slashLastIndex - 1);
6990
+ if (slashBeforeLastIndex === -1) {
6991
+ return url;
6992
+ }
6993
+ return `file://${resource.slice(0, slashBeforeLastIndex + 1)}`;
6994
+ }
6995
+ return `file://${resource.slice(0, slashLastIndex + 1)}`;
6996
+ }
6997
+ return new URL(url.endsWith("/") ? "../" : "./", url).href;
6998
+ };
6999
+
6968
7000
  const createServerEventsDispatcher = () => {
6969
7001
  const clients = [];
6970
7002
  const MAX_CLIENTS = 100;
@@ -7058,52 +7090,6 @@ const createServerEventsDispatcher = () => {
7058
7090
  };
7059
7091
  };
7060
7092
 
7061
- const lookupPackageDirectory = currentUrl => {
7062
- if (currentUrl === "file:///") {
7063
- return null;
7064
- }
7065
- const packageJsonFileUrl = `${currentUrl}package.json`;
7066
- if (existsSync(new URL(packageJsonFileUrl))) {
7067
- return currentUrl;
7068
- }
7069
- return lookupPackageDirectory(getParentUrl$1(currentUrl));
7070
- };
7071
- const getParentUrl$1 = url => {
7072
- if (url.startsWith("file://")) {
7073
- // With node.js new URL('../', 'file:///C:/').href
7074
- // returns "file:///C:/" instead of "file:///"
7075
- const resource = url.slice("file://".length);
7076
- const slashLastIndex = resource.lastIndexOf("/");
7077
- if (slashLastIndex === -1) {
7078
- return url;
7079
- }
7080
- const lastCharIndex = resource.length - 1;
7081
- if (slashLastIndex === lastCharIndex) {
7082
- const slashBeforeLastIndex = resource.lastIndexOf("/", slashLastIndex - 1);
7083
- if (slashBeforeLastIndex === -1) {
7084
- return url;
7085
- }
7086
- return `file://${resource.slice(0, slashBeforeLastIndex + 1)}`;
7087
- }
7088
- return `file://${resource.slice(0, slashLastIndex + 1)}`;
7089
- }
7090
- return new URL(url.endsWith("/") ? "../" : "./", url).href;
7091
- };
7092
-
7093
- const determineJsenvInternalDirectoryUrl = currentUrl => {
7094
- const packageDirectoryUrl = lookupPackageDirectory(currentUrl);
7095
- if (packageDirectoryUrl) {
7096
- return `${packageDirectoryUrl}.jsenv/${getDirectoryName(packageDirectoryUrl)}/`;
7097
- }
7098
- return `${currentUrl}.jsenv/`;
7099
- };
7100
- const getDirectoryName = directoryUrl => {
7101
- const {
7102
- pathname
7103
- } = new URL(directoryUrl);
7104
- return basename(pathname);
7105
- };
7106
-
7107
7093
  const watchSourceFiles = (sourceDirectoryUrl, callback, {
7108
7094
  sourceFileConfig = {},
7109
7095
  keepProcessAlive,
@@ -7118,8 +7104,9 @@ const watchSourceFiles = (sourceDirectoryUrl, callback, {
7118
7104
  const watchPatterns = {
7119
7105
  "**/*": true,
7120
7106
  // by default watch everything inside the source directory
7121
- "**/.*": false,
7122
- // file starting with a dot -> do not watch
7107
+ // line below is commented until @jsenv/url-meta fixes the fact that is matches
7108
+ // any file with an extension
7109
+ // "**/.*": false, // file starting with a dot -> do not watch
7123
7110
  "**/.*/": false,
7124
7111
  // directory starting with a dot -> do not watch
7125
7112
  "**/node_modules/": false,
@@ -7883,18 +7870,19 @@ const createUrlInfoTransformer = ({
7883
7870
  generatedUrlObject.searchParams.delete("as_js_classic_library");
7884
7871
  const urlForSourcemap = generatedUrlObject.href;
7885
7872
  urlInfo.sourcemapGeneratedUrl = generateSourcemapFileUrl(urlForSourcemap);
7886
- const [sourcemapReference, sourcemapUrlInfo] = injectSourcemapPlaceholder({
7887
- urlInfo,
7888
- specifier: urlInfo.sourcemapGeneratedUrl
7889
- });
7890
- urlInfo.sourcemapReference = sourcemapReference;
7891
- sourcemapUrlInfo.isInline = sourcemaps === "inline";
7892
7873
 
7893
7874
  // already loaded during "load" hook (happens during build)
7894
7875
  if (urlInfo.sourcemap) {
7876
+ const [sourcemapReference, sourcemapUrlInfo] = injectSourcemapPlaceholder({
7877
+ urlInfo,
7878
+ specifier: urlInfo.sourcemapGeneratedUrl
7879
+ });
7880
+ sourcemapUrlInfo.isInline = sourcemaps === "inline";
7881
+ urlInfo.sourcemapReference = sourcemapReference;
7895
7882
  urlInfo.sourcemap = normalizeSourcemap(urlInfo, urlInfo.sourcemap);
7896
7883
  return;
7897
7884
  }
7885
+
7898
7886
  // check for existing sourcemap for this content
7899
7887
  const sourcemapFound = SOURCEMAP.readComment({
7900
7888
  contentType: urlInfo.contentType,
@@ -7918,6 +7906,7 @@ const createUrlInfoTransformer = ({
7918
7906
  await context.cook(sourcemapUrlInfo, {
7919
7907
  reference: sourcemapReference
7920
7908
  });
7909
+ sourcemapUrlInfo.isInline = sourcemaps === "inline";
7921
7910
  const sourcemapRaw = JSON.parse(sourcemapUrlInfo.content);
7922
7911
  const sourcemap = normalizeSourcemap(urlInfo, sourcemapRaw);
7923
7912
  urlInfo.sourcemap = sourcemap;
@@ -7925,6 +7914,12 @@ const createUrlInfoTransformer = ({
7925
7914
  logger.error(`Error while handling existing sourcemap: ${e.message}`);
7926
7915
  return;
7927
7916
  }
7917
+ } else {
7918
+ const [, sourcemapUrlInfo] = injectSourcemapPlaceholder({
7919
+ urlInfo,
7920
+ specifier: urlInfo.sourcemapGeneratedUrl
7921
+ });
7922
+ sourcemapUrlInfo.isInline = sourcemaps === "inline";
7928
7923
  }
7929
7924
  };
7930
7925
  const applyIntermediateTransformations = (urlInfo, transformations) => {
@@ -8388,6 +8383,12 @@ const createResolveUrlError = ({
8388
8383
  reason: `no plugin has handled the specifier during "resolveUrl" hook`
8389
8384
  });
8390
8385
  }
8386
+ if (error.code === "DIRECTORY_REFERENCE_NOT_ALLOWED") {
8387
+ error.message = createDetailedMessage$1(error.message, {
8388
+ "reference trace": reference.trace.message
8389
+ });
8390
+ return error;
8391
+ }
8391
8392
  return createFailedToResolveUrlError({
8392
8393
  reason: `An error occured during specifier resolution`,
8393
8394
  ...detailsFromValueThrown(error)
@@ -8466,6 +8467,9 @@ const createTransformUrlContentError = ({
8466
8467
  urlInfo,
8467
8468
  error
8468
8469
  }) => {
8470
+ if (error.code === "DIRECTORY_REFERENCE_NOT_ALLOWED") {
8471
+ return error;
8472
+ }
8469
8473
  const createFailedToTransformError = ({
8470
8474
  code = error.code || "TRANSFORM_URL_CONTENT_ERROR",
8471
8475
  reason,
@@ -8750,7 +8754,6 @@ const createKitchen = ({
8750
8754
  signal,
8751
8755
  logLevel,
8752
8756
  rootDirectoryUrl,
8753
- jsenvInternalDirectoryUrl,
8754
8757
  urlGraph,
8755
8758
  dev = false,
8756
8759
  build = false,
@@ -8766,7 +8769,6 @@ const createKitchen = ({
8766
8769
  sourcemapsSourcesProtocol,
8767
8770
  sourcemapsSourcesContent,
8768
8771
  sourcemapsSourcesRelative,
8769
- writeGeneratedFiles,
8770
8772
  outDirectoryUrl
8771
8773
  }) => {
8772
8774
  const logger = createLogger({
@@ -8776,7 +8778,6 @@ const createKitchen = ({
8776
8778
  signal,
8777
8779
  logger,
8778
8780
  rootDirectoryUrl,
8779
- jsenvInternalDirectoryUrl,
8780
8781
  urlGraph,
8781
8782
  dev,
8782
8783
  build,
@@ -8836,6 +8837,7 @@ const createKitchen = ({
8836
8837
  assert,
8837
8838
  assertNode,
8838
8839
  typePropertyNode,
8840
+ leadsToADirectory = false,
8839
8841
  debug = false
8840
8842
  }) => {
8841
8843
  if (typeof specifier !== "string") {
@@ -8889,6 +8891,7 @@ const createKitchen = ({
8889
8891
  assert,
8890
8892
  assertNode,
8891
8893
  typePropertyNode,
8894
+ leadsToADirectory,
8892
8895
  mutation: null,
8893
8896
  debug
8894
8897
  };
@@ -9311,7 +9314,7 @@ ${ANSI.color(normalizedReturnValue, ANSI.YELLOW)}
9311
9314
  });
9312
9315
  };
9313
9316
  const cook = memoizeCook(async (urlInfo, context) => {
9314
- if (!writeGeneratedFiles || !outDirectoryUrl) {
9317
+ if (!outDirectoryUrl) {
9315
9318
  await _cook(urlInfo, context);
9316
9319
  return;
9317
9320
  }
@@ -10274,17 +10277,6 @@ const parseAndTransformWebmanifestUrls = async (urlInfo, context) => {
10274
10277
  const content = urlInfo.content;
10275
10278
  const manifest = JSON.parse(content);
10276
10279
  const actions = [];
10277
- const {
10278
- start_url
10279
- } = manifest;
10280
- if (start_url) {
10281
- if (context.build) {
10282
- manifest.start_url = "/";
10283
- } else {
10284
- const parentUrl = context.reference.parentUrl;
10285
- manifest.start_url = `${parentUrl.slice(context.rootDirectoryUrl.length)}`;
10286
- }
10287
- }
10288
10280
  const {
10289
10281
  icons = []
10290
10282
  } = manifest;
@@ -15226,7 +15218,7 @@ const jsenvPluginAsJsClassicLibrary = ({
15226
15218
  jsModuleUrlInfos: [jsModuleUrlInfo],
15227
15219
  context: {
15228
15220
  ...context,
15229
- buildDirectoryUrl: context.outDirectoryUrl
15221
+ buildDirectoryUrl: new URL("./", import.meta.url)
15230
15222
  },
15231
15223
  preserveDynamicImport: true
15232
15224
  });
@@ -16955,67 +16947,73 @@ const applyFileSystemMagicResolution = (fileUrl, {
16955
16947
  magicDirectoryIndex,
16956
16948
  magicExtensions
16957
16949
  }) => {
16958
- let lastENOENTError = null;
16959
- const fileStatOrNull = url => {
16950
+ const result = {
16951
+ stat: null,
16952
+ url: fileUrl,
16953
+ magicExtension: "",
16954
+ magicDirectoryIndex: false,
16955
+ lastENOENTError: null
16956
+ };
16957
+ if (fileStat === undefined) {
16960
16958
  try {
16961
- return statSync(new URL(url));
16959
+ fileStat = statSync(new URL(fileUrl));
16962
16960
  } catch (e) {
16963
16961
  if (e.code === "ENOENT") {
16964
- lastENOENTError = e;
16965
- return null;
16962
+ result.lastENOENTError = e;
16963
+ fileStat = null;
16964
+ } else {
16965
+ throw e;
16966
16966
  }
16967
- throw e;
16968
16967
  }
16969
- };
16970
- fileStat = fileStat === undefined ? fileStatOrNull(fileUrl) : fileStat;
16968
+ }
16971
16969
  if (fileStat && fileStat.isFile()) {
16972
- return {
16973
- found: true,
16974
- url: fileUrl
16975
- };
16970
+ result.stat = fileStat;
16971
+ result.url = fileUrl;
16972
+ return result;
16976
16973
  }
16977
16974
  if (fileStat && fileStat.isDirectory()) {
16978
16975
  if (magicDirectoryIndex) {
16979
16976
  const indexFileSuffix = fileUrl.endsWith("/") ? "index" : "/index";
16980
16977
  const indexFileUrl = `${fileUrl}${indexFileSuffix}`;
16981
- const result = applyFileSystemMagicResolution(indexFileUrl, {
16978
+ const subResult = applyFileSystemMagicResolution(indexFileUrl, {
16982
16979
  magicDirectoryIndex: false,
16983
16980
  magicExtensions
16984
16981
  });
16985
16982
  return {
16986
16983
  ...result,
16984
+ ...subResult,
16987
16985
  magicDirectoryIndex: true
16988
16986
  };
16989
16987
  }
16990
- return {
16991
- found: true,
16992
- url: fileUrl,
16993
- isDirectory: true
16994
- };
16988
+ result.stat = fileStat;
16989
+ result.url = fileUrl;
16990
+ return result;
16995
16991
  }
16996
16992
  if (magicExtensions && magicExtensions.length) {
16997
16993
  const parentUrl = new URL("./", fileUrl).href;
16998
16994
  const urlFilename = urlToFilename(fileUrl);
16999
- const extensionLeadingToFile = magicExtensions.find(extensionToTry => {
16995
+ for (const extensionToTry of magicExtensions) {
17000
16996
  const urlCandidate = `${parentUrl}${urlFilename}${extensionToTry}`;
17001
- const stat = fileStatOrNull(urlCandidate);
17002
- return stat;
17003
- });
17004
- if (extensionLeadingToFile) {
17005
- // magic extension worked
17006
- return {
17007
- found: true,
17008
- url: `${fileUrl}${extensionLeadingToFile}`,
17009
- magicExtension: extensionLeadingToFile
17010
- };
16997
+ let stat;
16998
+ try {
16999
+ stat = statSync(new URL(urlCandidate));
17000
+ } catch (e) {
17001
+ if (e.code === "ENOENT") {
17002
+ stat = null;
17003
+ } else {
17004
+ throw e;
17005
+ }
17006
+ }
17007
+ if (stat) {
17008
+ result.stat = stat;
17009
+ result.url = `${fileUrl}${extensionToTry}`;
17010
+ result.magicExtension = extensionToTry;
17011
+ return result;
17012
+ }
17011
17013
  }
17012
17014
  }
17013
17015
  // magic extension not found
17014
- return {
17015
- found: false,
17016
- url: fileUrl,
17017
- lastENOENTError
17018
- };
17016
+ return result;
17019
17017
  };
17020
17018
  const getExtensionsToTry = (magicExtensions, importer) => {
17021
17019
  if (!magicExtensions) {
@@ -17328,46 +17326,52 @@ const jsenvPluginFileUrls = ({
17328
17326
  const pathnameUsesTrailingSlash = pathname.endsWith("/");
17329
17327
  urlObject.search = "";
17330
17328
  urlObject.hash = "";
17331
- const foundADirectory = stat && stat.isDirectory();
17332
- const foundSomething = stat && !foundADirectory;
17333
17329
  // force trailing slash on directories
17334
- if (foundADirectory && !pathnameUsesTrailingSlash) {
17330
+ if (stat && stat.isDirectory() && !pathnameUsesTrailingSlash) {
17335
17331
  urlObject.pathname = `${pathname}/`;
17336
17332
  }
17337
17333
  // otherwise remove trailing slash if any
17338
- if (foundSomething && pathnameUsesTrailingSlash) {
17334
+ if (stat && !stat.isDirectory() && pathnameUsesTrailingSlash) {
17339
17335
  // a warning here? (because it's strange to reference a file with a trailing slash)
17340
17336
  urlObject.pathname = pathname.slice(0, -1);
17341
17337
  }
17342
- if (foundADirectory && directoryReferenceAllowed) {
17343
- if (
17344
- // ignore new URL second arg
17345
- reference.subtype === "new_url_second_arg" ||
17346
- // ignore root file url
17347
- reference.url === "file:///") {
17348
- reference.shouldHandle = false;
17349
- }
17350
- reference.data.foundADirectory = true;
17351
- const directoryFacadeUrl = urlObject.href;
17352
- const directoryUrlRaw = preserveSymlinks ? directoryFacadeUrl : resolveSymlink(directoryFacadeUrl);
17353
- const directoryUrl = `${directoryUrlRaw}${search}${hash}`;
17354
- return directoryUrl;
17355
- }
17356
- const url = urlObject.href;
17357
- const filesystemResolution = applyFileSystemMagicResolution(url, {
17358
- fileStat: stat,
17359
- magicDirectoryIndex,
17360
- magicExtensions: getExtensionsToTry(magicExtensions, reference.parentUrl)
17361
- });
17362
- if (!filesystemResolution.found) {
17363
- reference.data.foundADirectory = foundADirectory;
17364
- return null;
17338
+ let url = urlObject.href;
17339
+ const shouldPreserve = stat && stat.isDirectory() && (
17340
+ // ignore new URL second arg
17341
+ reference.subtype === "new_url_second_arg" ||
17342
+ // ignore root file url
17343
+ reference.url === "file:///" || reference.subtype === "new_url_first_arg" && reference.specifier === "./");
17344
+ if (shouldPreserve) {
17345
+ reference.shouldHandle = false;
17346
+ } else {
17347
+ const shouldApplyDilesystemMagicResolution = reference.type === "js_import";
17348
+ if (shouldApplyDilesystemMagicResolution) {
17349
+ const filesystemResolution = applyFileSystemMagicResolution(url, {
17350
+ fileStat: stat,
17351
+ magicDirectoryIndex,
17352
+ magicExtensions: getExtensionsToTry(magicExtensions, reference.parentUrl)
17353
+ });
17354
+ if (filesystemResolution.stat) {
17355
+ stat = filesystemResolution.stat;
17356
+ url = filesystemResolution.url;
17357
+ }
17358
+ }
17359
+ if (stat && stat.isDirectory()) {
17360
+ const directoryAllowed = reference.type === "filesystem" || typeof directoryReferenceAllowed === "function" && directoryReferenceAllowed(reference) || directoryReferenceAllowed;
17361
+ if (!directoryAllowed) {
17362
+ const error = new Error("Reference leads to a directory");
17363
+ error.code = "DIRECTORY_REFERENCE_NOT_ALLOWED";
17364
+ throw error;
17365
+ }
17366
+ }
17367
+ }
17368
+ reference.leadsToADirectory = stat && stat.isDirectory();
17369
+ if (stat) {
17370
+ const urlRaw = preserveSymlinks ? url : resolveSymlink(url);
17371
+ const resolvedUrl = `${urlRaw}${search}${hash}`;
17372
+ return resolvedUrl;
17365
17373
  }
17366
- reference.data.foundADirectory = filesystemResolution.isDirectory;
17367
- const fileFacadeUrl = filesystemResolution.url;
17368
- const fileUrlRaw = preserveSymlinks ? fileFacadeUrl : resolveSymlink(fileFacadeUrl);
17369
- const fileUrl = `${fileUrlRaw}${search}${hash}`;
17370
- return fileUrl;
17374
+ return null;
17371
17375
  }
17372
17376
  }, {
17373
17377
  name: "jsenv:filesystem_resolution",
@@ -17412,26 +17416,21 @@ const jsenvPluginFileUrls = ({
17412
17416
  return null;
17413
17417
  }
17414
17418
  const urlObject = new URL(urlInfo.url);
17415
- if (context.reference.data.foundADirectory) {
17416
- if (directoryReferenceAllowed) {
17417
- const directoryEntries = readdirSync(urlObject);
17418
- let filename;
17419
- if (context.reference.type === "filesystem") {
17420
- const parentUrlInfo = context.urlGraph.getUrlInfo(context.reference.parentUrl);
17421
- filename = `${parentUrlInfo.filename}${context.reference.specifier}/`;
17422
- } else {
17423
- filename = `${urlToFilename$1(urlInfo.url)}/`;
17424
- }
17425
- return {
17426
- type: "directory",
17427
- contentType: "application/json",
17428
- content: JSON.stringify(directoryEntries, null, " "),
17429
- filename
17430
- };
17419
+ if (context.reference.leadsToADirectory) {
17420
+ const directoryEntries = readdirSync(urlObject);
17421
+ let filename;
17422
+ if (context.reference.type === "filesystem") {
17423
+ const parentUrlInfo = context.urlGraph.getUrlInfo(context.reference.parentUrl);
17424
+ filename = `${parentUrlInfo.filename}${context.reference.specifier}/`;
17425
+ } else {
17426
+ filename = `${urlToFilename$1(urlInfo.url)}/`;
17431
17427
  }
17432
- const error = new Error("found a directory on filesystem");
17433
- error.code = "DIRECTORY_REFERENCE_NOT_ALLOWED";
17434
- throw error;
17428
+ return {
17429
+ type: "directory",
17430
+ contentType: "application/json",
17431
+ content: JSON.stringify(directoryEntries, null, " "),
17432
+ filename
17433
+ };
17435
17434
  }
17436
17435
  const fileBuffer = readFileSync$1(urlObject);
17437
17436
  const contentType = CONTENT_TYPE.fromUrlExtension(urlInfo.url);
@@ -20882,7 +20881,7 @@ const build = async ({
20882
20881
  watch = false,
20883
20882
  directoryToClean,
20884
20883
  writeOnFileSystem = true,
20885
- writeGeneratedFiles = false,
20884
+ outDirectoryUrl,
20886
20885
  assetManifest = versioningMethod === "filename",
20887
20886
  assetManifestFileRelativeUrl = "asset-manifest.json",
20888
20887
  ...rest
@@ -20894,6 +20893,15 @@ const build = async ({
20894
20893
  throw new TypeError(`${unexpectedParamNames.join(",")}: there is no such param`);
20895
20894
  }
20896
20895
  sourceDirectoryUrl = assertAndNormalizeDirectoryUrl(sourceDirectoryUrl, "sourceDirectoryUrl");
20896
+ buildDirectoryUrl = assertAndNormalizeDirectoryUrl(buildDirectoryUrl, "buildDirectoryUrl");
20897
+ if (outDirectoryUrl === undefined) {
20898
+ const packageDirectoryUrl = lookupPackageDirectory(sourceDirectoryUrl);
20899
+ if (packageDirectoryUrl) {
20900
+ outDirectoryUrl = `${packageDirectoryUrl}.jsenv/`;
20901
+ }
20902
+ } else {
20903
+ outDirectoryUrl = assertAndNormalizeDirectoryUrl(outDirectoryUrl, "outDirectoryUrl");
20904
+ }
20897
20905
  if (typeof entryPoints !== "object" || entryPoints === null) {
20898
20906
  throw new TypeError(`entryPoints must be an object, got ${entryPoints}`);
20899
20907
  }
@@ -20910,7 +20918,6 @@ const build = async ({
20910
20918
  throw new TypeError(`entryPoints values must be plain strings (no "/"), found "${value}" on key "${key}"`);
20911
20919
  }
20912
20920
  });
20913
- buildDirectoryUrl = assertAndNormalizeDirectoryUrl(buildDirectoryUrl, "buildDirectoryUrl");
20914
20921
  if (!["filename", "search_param"].includes(versioningMethod)) {
20915
20922
  throw new TypeError(`versioningMethod must be "filename" or "search_param", got ${versioning}`);
20916
20923
  }
@@ -20934,7 +20941,6 @@ const build = async ({
20934
20941
  directoryToClean = new URL(assetsDirectory, buildDirectoryUrl).href;
20935
20942
  }
20936
20943
  }
20937
- const jsenvInternalDirectoryUrl = determineJsenvInternalDirectoryUrl(sourceDirectoryUrl);
20938
20944
  const asFormattedBuildUrl = (generatedUrl, reference) => {
20939
20945
  if (base === "./") {
20940
20946
  const urlRelativeToParent = urlToRelativeUrl(generatedUrl, reference.parentUrl === sourceDirectoryUrl ? buildDirectoryUrl : reference.parentUrl);
@@ -20988,7 +20994,6 @@ build ${entryPointKeys.length} entry points`);
20988
20994
  signal,
20989
20995
  logLevel,
20990
20996
  rootDirectoryUrl: sourceDirectoryUrl,
20991
- jsenvInternalDirectoryUrl,
20992
20997
  urlGraph: rawGraph,
20993
20998
  build: true,
20994
20999
  runtimeCompat,
@@ -21023,8 +21028,7 @@ build ${entryPointKeys.length} entry points`);
21023
21028
  })],
21024
21029
  sourcemaps,
21025
21030
  sourcemapsSourcesContent,
21026
- writeGeneratedFiles,
21027
- outDirectoryUrl: new URL("build/", jsenvInternalDirectoryUrl)
21031
+ outDirectoryUrl: outDirectoryUrl ? new URL("build/", outDirectoryUrl) : undefined
21028
21032
  });
21029
21033
  const buildUrlsGenerator = createBuildUrlsGenerator({
21030
21034
  buildDirectoryUrl,
@@ -21052,7 +21056,6 @@ ${ANSI.color(buildUrl, ANSI.MAGENTA)}
21052
21056
  const finalGraphKitchen = createKitchen({
21053
21057
  logLevel,
21054
21058
  rootDirectoryUrl: buildDirectoryUrl,
21055
- jsenvInternalDirectoryUrl,
21056
21059
  urlGraph: finalGraph,
21057
21060
  build: true,
21058
21061
  runtimeCompat,
@@ -21298,8 +21301,7 @@ ${ANSI.color(buildUrl, ANSI.MAGENTA)}
21298
21301
  sourcemaps,
21299
21302
  sourcemapsSourcesContent,
21300
21303
  sourcemapsSourcesRelative: !versioning,
21301
- writeGeneratedFiles,
21302
- outDirectoryUrl: new URL("postbuild/", jsenvInternalDirectoryUrl)
21304
+ outDirectoryUrl: outDirectoryUrl ? new URL("postbuild/", outDirectoryUrl) : undefined
21303
21305
  });
21304
21306
  const finalEntryUrls = [];
21305
21307
  {
@@ -21307,8 +21309,8 @@ ${ANSI.color(buildUrl, ANSI.MAGENTA)}
21307
21309
  disabled: logger.levels.debug || !logger.levels.info
21308
21310
  });
21309
21311
  try {
21310
- if (writeGeneratedFiles) {
21311
- await ensureEmptyDirectory(new URL(`build/`, sourceDirectoryUrl));
21312
+ if (outDirectoryUrl) {
21313
+ await ensureEmptyDirectory(new URL(`build/`, outDirectoryUrl));
21312
21314
  }
21313
21315
  const rawUrlGraphLoader = createUrlGraphLoader(rawGraphKitchen.kitchenContext);
21314
21316
  Object.keys(entryPoints).forEach(key => {
@@ -21521,8 +21523,8 @@ ${ANSI.color(buildUrl, ANSI.MAGENTA)}
21521
21523
  disabled: logger.levels.debug || !logger.levels.info
21522
21524
  });
21523
21525
  try {
21524
- if (writeGeneratedFiles) {
21525
- await ensureEmptyDirectory(new URL(`postbuild/`, jsenvInternalDirectoryUrl));
21526
+ if (outDirectoryUrl) {
21527
+ await ensureEmptyDirectory(new URL(`postbuild/`, outDirectoryUrl));
21526
21528
  }
21527
21529
  const finalUrlGraphLoader = createUrlGraphLoader(finalGraphKitchen.kitchenContext);
21528
21530
  entryUrls.forEach(entryUrl => {
@@ -21722,7 +21724,6 @@ ${ANSI.color(buildUrl, ANSI.MAGENTA)}
21722
21724
  const versioningKitchen = createKitchen({
21723
21725
  logLevel: logger.level,
21724
21726
  rootDirectoryUrl: buildDirectoryUrl,
21725
- jsenvInternalDirectoryUrl,
21726
21727
  urlGraph: finalGraph,
21727
21728
  build: true,
21728
21729
  runtimeCompat,
@@ -21814,8 +21815,7 @@ ${ANSI.color(buildUrl, ANSI.MAGENTA)}
21814
21815
  sourcemaps,
21815
21816
  sourcemapsSourcesContent,
21816
21817
  sourcemapsSourcesRelative: true,
21817
- writeGeneratedFiles,
21818
- outDirectoryUrl: new URL("postbuild/", jsenvInternalDirectoryUrl)
21818
+ outDirectoryUrl: outDirectoryUrl ? new URL("postbuild/", outDirectoryUrl) : undefined
21819
21819
  });
21820
21820
  const versioningUrlGraphLoader = createUrlGraphLoader(versioningKitchen.kitchenContext);
21821
21821
  finalEntryUrls.forEach(finalEntryUrl => {
@@ -22343,7 +22343,7 @@ const createFileService = ({
22343
22343
  sourcemaps,
22344
22344
  sourcemapsSourcesProtocol,
22345
22345
  sourcemapsSourcesContent,
22346
- writeGeneratedFiles
22346
+ outDirectoryUrl
22347
22347
  }) => {
22348
22348
  const clientFileChangeCallbackList = [];
22349
22349
  const clientFilesPruneCallbackList = [];
@@ -22392,7 +22392,6 @@ const createFileService = ({
22392
22392
  const clientRuntimeCompat = {
22393
22393
  [runtimeName]: runtimeVersion
22394
22394
  };
22395
- const jsenvInternalDirectoryUrl = determineJsenvInternalDirectoryUrl(sourceDirectoryUrl);
22396
22395
  let mainFileUrl;
22397
22396
  if (sourceMainFilePath === undefined) {
22398
22397
  mainFileUrl = explorer ? String(explorerHtmlFileUrl) : String(new URL("./index.html", sourceDirectoryUrl));
@@ -22403,7 +22402,6 @@ const createFileService = ({
22403
22402
  signal,
22404
22403
  logLevel,
22405
22404
  rootDirectoryUrl: sourceDirectoryUrl,
22406
- jsenvInternalDirectoryUrl,
22407
22405
  urlGraph,
22408
22406
  dev: true,
22409
22407
  runtimeCompat,
@@ -22430,8 +22428,7 @@ const createFileService = ({
22430
22428
  sourcemaps,
22431
22429
  sourcemapsSourcesProtocol,
22432
22430
  sourcemapsSourcesContent,
22433
- writeGeneratedFiles,
22434
- outDirectoryUrl: new URL(`${runtimeName}@${runtimeVersion}/`, jsenvInternalDirectoryUrl)
22431
+ outDirectoryUrl: outDirectoryUrl ? new URL(`${runtimeName}@${runtimeVersion}/`, outDirectoryUrl) : undefined
22435
22432
  });
22436
22433
  urlGraph.createUrlInfoCallbackRef.current = urlInfo => {
22437
22434
  const {
@@ -22777,9 +22774,7 @@ const startDevServer = async ({
22777
22774
  sourcemaps = "inline",
22778
22775
  sourcemapsSourcesProtocol,
22779
22776
  sourcemapsSourcesContent,
22780
- // no real need to write files during github workflow
22781
- // and mitigates https://github.com/actions/runner-images/issues/3885
22782
- writeGeneratedFiles = !process.env.CI,
22777
+ outDirectoryUrl,
22783
22778
  ...rest
22784
22779
  }) => {
22785
22780
  // params type checking
@@ -22789,6 +22784,14 @@ const startDevServer = async ({
22789
22784
  throw new TypeError(`${unexpectedParamNames.join(",")}: there is no such param`);
22790
22785
  }
22791
22786
  sourceDirectoryUrl = assertAndNormalizeDirectoryUrl(sourceDirectoryUrl, "sourceDirectoryUrl");
22787
+ if (outDirectoryUrl === undefined) {
22788
+ const packageDirectoryUrl = lookupPackageDirectory(sourceDirectoryUrl);
22789
+ if (packageDirectoryUrl) {
22790
+ outDirectoryUrl = `${packageDirectoryUrl}.jsenv/`;
22791
+ }
22792
+ } else {
22793
+ outDirectoryUrl = assertAndNormalizeDirectoryUrl(outDirectoryUrl, "outDirectoryUrl");
22794
+ }
22792
22795
  }
22793
22796
  const logger = createLogger({
22794
22797
  logLevel
@@ -22881,7 +22884,7 @@ const startDevServer = async ({
22881
22884
  sourcemaps,
22882
22885
  sourcemapsSourcesProtocol,
22883
22886
  sourcemapsSourcesContent,
22884
- writeGeneratedFiles
22887
+ outDirectoryUrl
22885
22888
  }),
22886
22889
  handleWebsocket: (websocket, {
22887
22890
  request
@@ -24669,7 +24672,7 @@ const executeTestPlan = async ({
24669
24672
  await import(devServerModuleUrl);
24670
24673
  delete process.env.IMPORTED_BY_TEST_PLAN;
24671
24674
  } catch (e) {
24672
- if (e.code === "MODULE_NOT_FOUND") {
24675
+ if (e.code === "ERR_MODULE_NOT_FOUND") {
24673
24676
  throw new Error(`Cannot find file responsible to start dev server at "${devServerModuleUrl}"`);
24674
24677
  }
24675
24678
  throw e;