@jsenv/core 40.4.0 → 40.5.1

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.
@@ -5669,28 +5669,63 @@ const createBuildPackageConditions = (
5669
5669
  const nodeRuntimeEnabled = Object.keys(runtimeCompat).includes("node");
5670
5670
  // https://nodejs.org/api/esm.html#resolver-algorithm-specification
5671
5671
  const processArgConditions = readCustomConditionsFromProcessArgs();
5672
- const packageConditionsDefaultResolvers = {};
5673
- for (const processArgCondition of processArgConditions) {
5674
- packageConditionsDefaultResolvers[processArgCondition] = true;
5675
- }
5676
- const packageConditionResolvers = {
5677
- ...packageConditionsDefaultResolvers,
5678
- development: (specifier, importer) => {
5679
- if (isBareSpecifier$1(specifier)) {
5680
- const { url } = applyNodeEsmResolution({
5681
- specifier,
5682
- parentUrl: importer,
5683
- });
5684
- return !url.includes("/node_modules/");
5672
+ const devResolver = (specifier, importer) => {
5673
+ if (isBareSpecifier$1(specifier)) {
5674
+ const { url } = applyNodeEsmResolution({
5675
+ specifier,
5676
+ parentUrl: importer,
5677
+ });
5678
+ return !url.includes("/node_modules/");
5679
+ }
5680
+ return !importer.includes("/node_modules/");
5681
+ };
5682
+
5683
+ const conditionDefaultResolvers = {
5684
+ "dev:*": devResolver,
5685
+ "development": devResolver,
5686
+ "node": nodeRuntimeEnabled,
5687
+ "browser": !nodeRuntimeEnabled,
5688
+ "import": true,
5689
+ };
5690
+ const conditionResolvers = {
5691
+ ...conditionDefaultResolvers,
5692
+ };
5693
+
5694
+ let wildcardToRemoveSet = new Set();
5695
+ const addCustomResolver = (condition, customResolver) => {
5696
+ for (const conditionCandidate of Object.keys(conditionDefaultResolvers)) {
5697
+ if (conditionCandidate.includes("*")) {
5698
+ const conditionRegex = new RegExp(
5699
+ `^${conditionCandidate.replace(/\*/g, "(.*)")}$`,
5700
+ );
5701
+ if (conditionRegex.test(condition)) {
5702
+ const existingResolver =
5703
+ conditionDefaultResolvers[conditionCandidate];
5704
+ wildcardToRemoveSet.add(conditionCandidate);
5705
+ conditionResolvers[condition] = combineTwoPackageConditionResolvers(
5706
+ existingResolver,
5707
+ customResolver,
5708
+ );
5709
+ return;
5710
+ }
5685
5711
  }
5686
- return !importer.includes("/node_modules/");
5687
- },
5688
- node: nodeRuntimeEnabled,
5689
- browser: !nodeRuntimeEnabled,
5690
- import: true,
5712
+ }
5713
+ const existingResolver = conditionDefaultResolvers[condition];
5714
+ if (existingResolver) {
5715
+ conditionResolvers[condition] = combineTwoPackageConditionResolvers(
5716
+ existingResolver,
5717
+ customResolver,
5718
+ );
5719
+ return;
5720
+ }
5721
+ conditionResolvers[condition] = customResolver;
5691
5722
  };
5692
- for (const condition of Object.keys(packageConditions)) {
5693
- const value = packageConditions[condition];
5723
+
5724
+ for (const processArgCondition of processArgConditions) {
5725
+ addCustomResolver(processArgCondition, true);
5726
+ }
5727
+ for (const customCondition of Object.keys(packageConditions)) {
5728
+ const value = packageConditions[customCondition];
5694
5729
  let customResolver;
5695
5730
  if (typeof value === "object") {
5696
5731
  const associations = URL_META.resolveAssociations(
@@ -5733,29 +5768,25 @@ const createBuildPackageConditions = (
5733
5768
  } else if (typeof value === "function") {
5734
5769
  customResolver = value;
5735
5770
  } else {
5736
- customResolver = () => value;
5737
- }
5738
- const existing = packageConditionResolvers[condition];
5739
- if (existing) {
5740
- packageConditionResolvers[condition] = (...args) => {
5741
- const customResult = customResolver(...args);
5742
- return customResult === undefined ? existing(...args) : customResult;
5743
- };
5744
- } else {
5745
- packageConditionResolvers[condition] = customResolver;
5771
+ customResolver = value;
5746
5772
  }
5773
+ addCustomResolver(customCondition, customResolver);
5774
+ }
5775
+
5776
+ for (const wildcardToRemove of wildcardToRemoveSet) {
5777
+ delete conditionResolvers[wildcardToRemove];
5747
5778
  }
5748
5779
 
5780
+ const conditionCandidateArray = Object.keys(conditionResolvers);
5749
5781
  return (specifier, importer) => {
5750
5782
  const conditions = [];
5751
- for (const conditionCandidate of Object.keys(packageConditionResolvers)) {
5752
- const packageConditionResolver =
5753
- packageConditionResolvers[conditionCandidate];
5754
- if (typeof packageConditionResolver === "function") {
5755
- if (packageConditionResolver(specifier, importer)) {
5783
+ for (const conditionCandidate of conditionCandidateArray) {
5784
+ const conditionResolver = conditionResolvers[conditionCandidate];
5785
+ if (typeof conditionResolver === "function") {
5786
+ if (conditionResolver(specifier, importer)) {
5756
5787
  conditions.push(conditionCandidate);
5757
5788
  }
5758
- } else if (packageConditionResolver) {
5789
+ } else if (conditionResolver) {
5759
5790
  conditions.push(conditionCandidate);
5760
5791
  }
5761
5792
  }
@@ -5763,6 +5794,22 @@ const createBuildPackageConditions = (
5763
5794
  };
5764
5795
  };
5765
5796
 
5797
+ const combineTwoPackageConditionResolvers = (first, second) => {
5798
+ if (typeof second !== "function") {
5799
+ return second;
5800
+ }
5801
+ return (...args) => {
5802
+ const secondResult = second(...args);
5803
+ if (secondResult !== undefined) {
5804
+ return secondResult;
5805
+ }
5806
+ if (typeof first === "function") {
5807
+ return first(...args);
5808
+ }
5809
+ return first;
5810
+ };
5811
+ };
5812
+
5766
5813
  const addRelationshipWithPackageJson = ({
5767
5814
  reference,
5768
5815
  packageJsonUrl,
@@ -10726,7 +10773,12 @@ const build = async ({
10726
10773
  let runtimeType;
10727
10774
  {
10728
10775
  if (isBareSpecifier(key)) {
10729
- const packageConditions = ["development", "node", "import"];
10776
+ const packageConditions = [
10777
+ "development",
10778
+ "dev:*",
10779
+ "node",
10780
+ "import",
10781
+ ];
10730
10782
  try {
10731
10783
  const { url, type } = applyNodeEsmResolution({
10732
10784
  conditions: packageConditions,
@@ -10902,7 +10954,42 @@ const build = async ({
10902
10954
  { sourceUrlToLog, buildUrlToLog },
10903
10955
  ) => {
10904
10956
  let content = "";
10905
- content += `${UNICODE.OK} ${ANSI.color(sourceUrlToLog, ANSI.GREY)} ${ANSI.color("->", ANSI.GREY)} ${ANSI.color(buildUrlToLog, "")}`;
10957
+
10958
+ const applyColorOnFileRelativeUrl = (fileRelativeUrl, color) => {
10959
+ const fileUrl = new URL(fileRelativeUrl, rootPackageDirectoryUrl);
10960
+ const packageDirectoryUrl = lookupPackageDirectory(fileUrl);
10961
+ if (
10962
+ !packageDirectoryUrl ||
10963
+ packageDirectoryUrl === rootPackageDirectoryUrl
10964
+ ) {
10965
+ return ANSI.color(fileRelativeUrl, color);
10966
+ }
10967
+ const parentDirectoryUrl = new URL("../", packageDirectoryUrl).href;
10968
+ const beforePackageDirectoryName = urlToRelativeUrl(
10969
+ parentDirectoryUrl,
10970
+ rootPackageDirectoryUrl,
10971
+ );
10972
+ const packageDirectoryName = urlToFilename(packageDirectoryUrl);
10973
+ const afterPackageDirectoryUrl = urlToRelativeUrl(
10974
+ fileUrl,
10975
+ packageDirectoryUrl,
10976
+ );
10977
+ const beforePackageNameStylized = ANSI.color(
10978
+ beforePackageDirectoryName,
10979
+ color,
10980
+ );
10981
+ const packageNameStylized = ANSI.color(
10982
+ ANSI.effect(packageDirectoryName, ANSI.UNDERLINE),
10983
+ color,
10984
+ );
10985
+ const afterPackageNameStylized = ANSI.color(
10986
+ `/${afterPackageDirectoryUrl}`,
10987
+ color,
10988
+ );
10989
+ return `${beforePackageNameStylized}${packageNameStylized}${afterPackageNameStylized}`;
10990
+ };
10991
+
10992
+ content += `${UNICODE.OK} ${applyColorOnFileRelativeUrl(sourceUrlToLog, ANSI.GREY)} ${ANSI.color("->", ANSI.GREY)} ${applyColorOnFileRelativeUrl(buildUrlToLog, "")}`;
10906
10993
  // content += " ";
10907
10994
  // content += ANSI.color("(", ANSI.GREY);
10908
10995
  // content += ANSI.color(
@@ -11407,6 +11494,7 @@ const entryPointDefaultParams = {
11407
11494
  scenarioPlaceholders: undefined,
11408
11495
  injections: undefined,
11409
11496
  transpilation: {},
11497
+ preserveComments: undefined,
11410
11498
 
11411
11499
  versioningMethod: "search_param", // "filename", "search_param"
11412
11500
  versioningViaImportmap: true,
@@ -11458,6 +11546,7 @@ const prepareEntryPointBuild = async (
11458
11546
  scenarioPlaceholders,
11459
11547
  injections,
11460
11548
  transpilation,
11549
+ preserveComments,
11461
11550
 
11462
11551
  versioningMethod,
11463
11552
  versioningViaImportmap,
@@ -11533,6 +11622,9 @@ const prepareEntryPointBuild = async (
11533
11622
  if (entryPointParams.assetManifest === undefined) {
11534
11623
  assetManifest = versioningMethod === "filename";
11535
11624
  }
11625
+ if (entryPointParams.preserveComments === undefined) {
11626
+ preserveComments = someEntryPointUseNode;
11627
+ }
11536
11628
  }
11537
11629
 
11538
11630
  const buildOperation = Abort.startOperation();
@@ -11591,7 +11683,7 @@ const prepareEntryPointBuild = async (
11591
11683
  },
11592
11684
  ...plugins,
11593
11685
  ...(bundling ? [jsenvPluginBundling(bundling)] : []),
11594
- ...(minification ? [jsenvPluginMinification(minification)] : []),
11686
+ jsenvPluginMinification(minification, { preserveComments }),
11595
11687
  ...getCorePlugins({
11596
11688
  packageDirectory,
11597
11689
  rootDirectoryUrl: sourceDirectoryUrl,
@@ -5144,6 +5144,9 @@ const bufferToEtag = (buffer) => {
5144
5144
 
5145
5145
  // https://nodejs.org/api/packages.html#resolving-user-conditions
5146
5146
  const readCustomConditionsFromProcessArgs = () => {
5147
+ if (process.env.IGNORE_PACKAGE_CONDITIONS) {
5148
+ return [];
5149
+ }
5147
5150
  const packageConditions = [];
5148
5151
  for (const arg of process.execArgv) {
5149
5152
  if (arg.includes("-C=")) {
@@ -5874,7 +5877,27 @@ const applyPackageTargetResolution = (target, resolutionContext) => {
5874
5877
  if (Number.isInteger(key)) {
5875
5878
  throw new Error("Invalid package configuration");
5876
5879
  }
5877
- if (key === "default" || conditions.includes(key)) {
5880
+ let matched;
5881
+ if (key === "default") {
5882
+ matched = true;
5883
+ } else {
5884
+ for (const conditionCandidate of conditions) {
5885
+ if (conditionCandidate === key) {
5886
+ matched = true;
5887
+ break;
5888
+ }
5889
+ if (conditionCandidate.includes("*")) {
5890
+ const conditionCandidateRegex = new RegExp(
5891
+ `^${conditionCandidate.replace(/\*/g, "(.*)")}$`,
5892
+ );
5893
+ if (conditionCandidateRegex.test(key)) {
5894
+ matched = true;
5895
+ break;
5896
+ }
5897
+ }
5898
+ }
5899
+ }
5900
+ if (matched) {
5878
5901
  const targetValue = target[key];
5879
5902
  const resolved = applyPackageTargetResolution(targetValue, {
5880
5903
  ...resolutionContext,
@@ -3726,6 +3726,9 @@ const bufferToEtag = (buffer) => {
3726
3726
 
3727
3727
  // https://nodejs.org/api/packages.html#resolving-user-conditions
3728
3728
  const readCustomConditionsFromProcessArgs = () => {
3729
+ if (process.env.IGNORE_PACKAGE_CONDITIONS) {
3730
+ return [];
3731
+ }
3729
3732
  const packageConditions = [];
3730
3733
  for (const arg of process.execArgv) {
3731
3734
  if (arg.includes("-C=")) {
@@ -4456,7 +4459,27 @@ const applyPackageTargetResolution = (target, resolutionContext) => {
4456
4459
  if (Number.isInteger(key)) {
4457
4460
  throw new Error("Invalid package configuration");
4458
4461
  }
4459
- if (key === "default" || conditions.includes(key)) {
4462
+ let matched;
4463
+ if (key === "default") {
4464
+ matched = true;
4465
+ } else {
4466
+ for (const conditionCandidate of conditions) {
4467
+ if (conditionCandidate === key) {
4468
+ matched = true;
4469
+ break;
4470
+ }
4471
+ if (conditionCandidate.includes("*")) {
4472
+ const conditionCandidateRegex = new RegExp(
4473
+ `^${conditionCandidate.replace(/\*/g, "(.*)")}$`,
4474
+ );
4475
+ if (conditionCandidateRegex.test(key)) {
4476
+ matched = true;
4477
+ break;
4478
+ }
4479
+ }
4480
+ }
4481
+ }
4482
+ if (matched) {
4460
4483
  const targetValue = target[key];
4461
4484
  const resolved = applyPackageTargetResolution(targetValue, {
4462
4485
  ...resolutionContext,
@@ -5374,28 +5374,63 @@ const createBuildPackageConditions = (
5374
5374
  const nodeRuntimeEnabled = Object.keys(runtimeCompat).includes("node");
5375
5375
  // https://nodejs.org/api/esm.html#resolver-algorithm-specification
5376
5376
  const processArgConditions = readCustomConditionsFromProcessArgs();
5377
- const packageConditionsDefaultResolvers = {};
5378
- for (const processArgCondition of processArgConditions) {
5379
- packageConditionsDefaultResolvers[processArgCondition] = true;
5380
- }
5381
- const packageConditionResolvers = {
5382
- ...packageConditionsDefaultResolvers,
5383
- development: (specifier, importer) => {
5384
- if (isBareSpecifier(specifier)) {
5385
- const { url } = applyNodeEsmResolution({
5386
- specifier,
5387
- parentUrl: importer,
5388
- });
5389
- return !url.includes("/node_modules/");
5377
+ const devResolver = (specifier, importer) => {
5378
+ if (isBareSpecifier(specifier)) {
5379
+ const { url } = applyNodeEsmResolution({
5380
+ specifier,
5381
+ parentUrl: importer,
5382
+ });
5383
+ return !url.includes("/node_modules/");
5384
+ }
5385
+ return !importer.includes("/node_modules/");
5386
+ };
5387
+
5388
+ const conditionDefaultResolvers = {
5389
+ "dev:*": devResolver,
5390
+ "development": devResolver,
5391
+ "node": nodeRuntimeEnabled,
5392
+ "browser": !nodeRuntimeEnabled,
5393
+ "import": true,
5394
+ };
5395
+ const conditionResolvers = {
5396
+ ...conditionDefaultResolvers,
5397
+ };
5398
+
5399
+ let wildcardToRemoveSet = new Set();
5400
+ const addCustomResolver = (condition, customResolver) => {
5401
+ for (const conditionCandidate of Object.keys(conditionDefaultResolvers)) {
5402
+ if (conditionCandidate.includes("*")) {
5403
+ const conditionRegex = new RegExp(
5404
+ `^${conditionCandidate.replace(/\*/g, "(.*)")}$`,
5405
+ );
5406
+ if (conditionRegex.test(condition)) {
5407
+ const existingResolver =
5408
+ conditionDefaultResolvers[conditionCandidate];
5409
+ wildcardToRemoveSet.add(conditionCandidate);
5410
+ conditionResolvers[condition] = combineTwoPackageConditionResolvers(
5411
+ existingResolver,
5412
+ customResolver,
5413
+ );
5414
+ return;
5415
+ }
5390
5416
  }
5391
- return !importer.includes("/node_modules/");
5392
- },
5393
- node: nodeRuntimeEnabled,
5394
- browser: !nodeRuntimeEnabled,
5395
- import: true,
5417
+ }
5418
+ const existingResolver = conditionDefaultResolvers[condition];
5419
+ if (existingResolver) {
5420
+ conditionResolvers[condition] = combineTwoPackageConditionResolvers(
5421
+ existingResolver,
5422
+ customResolver,
5423
+ );
5424
+ return;
5425
+ }
5426
+ conditionResolvers[condition] = customResolver;
5396
5427
  };
5397
- for (const condition of Object.keys(packageConditions)) {
5398
- const value = packageConditions[condition];
5428
+
5429
+ for (const processArgCondition of processArgConditions) {
5430
+ addCustomResolver(processArgCondition, true);
5431
+ }
5432
+ for (const customCondition of Object.keys(packageConditions)) {
5433
+ const value = packageConditions[customCondition];
5399
5434
  let customResolver;
5400
5435
  if (typeof value === "object") {
5401
5436
  const associations = URL_META.resolveAssociations(
@@ -5438,29 +5473,25 @@ const createBuildPackageConditions = (
5438
5473
  } else if (typeof value === "function") {
5439
5474
  customResolver = value;
5440
5475
  } else {
5441
- customResolver = () => value;
5442
- }
5443
- const existing = packageConditionResolvers[condition];
5444
- if (existing) {
5445
- packageConditionResolvers[condition] = (...args) => {
5446
- const customResult = customResolver(...args);
5447
- return customResult === undefined ? existing(...args) : customResult;
5448
- };
5449
- } else {
5450
- packageConditionResolvers[condition] = customResolver;
5476
+ customResolver = value;
5451
5477
  }
5478
+ addCustomResolver(customCondition, customResolver);
5452
5479
  }
5453
5480
 
5481
+ for (const wildcardToRemove of wildcardToRemoveSet) {
5482
+ delete conditionResolvers[wildcardToRemove];
5483
+ }
5484
+
5485
+ const conditionCandidateArray = Object.keys(conditionResolvers);
5454
5486
  return (specifier, importer) => {
5455
5487
  const conditions = [];
5456
- for (const conditionCandidate of Object.keys(packageConditionResolvers)) {
5457
- const packageConditionResolver =
5458
- packageConditionResolvers[conditionCandidate];
5459
- if (typeof packageConditionResolver === "function") {
5460
- if (packageConditionResolver(specifier, importer)) {
5488
+ for (const conditionCandidate of conditionCandidateArray) {
5489
+ const conditionResolver = conditionResolvers[conditionCandidate];
5490
+ if (typeof conditionResolver === "function") {
5491
+ if (conditionResolver(specifier, importer)) {
5461
5492
  conditions.push(conditionCandidate);
5462
5493
  }
5463
- } else if (packageConditionResolver) {
5494
+ } else if (conditionResolver) {
5464
5495
  conditions.push(conditionCandidate);
5465
5496
  }
5466
5497
  }
@@ -5468,6 +5499,22 @@ const createBuildPackageConditions = (
5468
5499
  };
5469
5500
  };
5470
5501
 
5502
+ const combineTwoPackageConditionResolvers = (first, second) => {
5503
+ if (typeof second !== "function") {
5504
+ return second;
5505
+ }
5506
+ return (...args) => {
5507
+ const secondResult = second(...args);
5508
+ if (secondResult !== undefined) {
5509
+ return secondResult;
5510
+ }
5511
+ if (typeof first === "function") {
5512
+ return first(...args);
5513
+ }
5514
+ return first;
5515
+ };
5516
+ };
5517
+
5471
5518
  const addRelationshipWithPackageJson = ({
5472
5519
  reference,
5473
5520
  packageJsonUrl,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jsenv/core",
3
- "version": "40.4.0",
3
+ "version": "40.5.1",
4
4
  "description": "Tool to develop, test and build js projects",
5
5
  "license": "MIT",
6
6
  "author": {
@@ -22,7 +22,7 @@
22
22
  "exports": {
23
23
  ".": {
24
24
  "import": {
25
- "development": "./src/main.js",
25
+ "dev:jsenv": "./src/main.js",
26
26
  "default": "./dist/jsenv_core.js"
27
27
  }
28
28
  },
@@ -55,9 +55,9 @@
55
55
  ],
56
56
  "scripts": {
57
57
  "eslint": "npx eslint .",
58
- "test": "node --conditions=development ./scripts/test/test.mjs",
58
+ "test": "node --conditions=dev:jsenv ./scripts/test/test.mjs",
59
59
  "test:packages": "npm run test -- ./packages/",
60
- "build": "node --conditions=development ./scripts/build/build.mjs",
60
+ "build": "node --conditions=dev:jsenv ./scripts/build/build.mjs",
61
61
  "build:packages": "npm run build --workspaces --if-present --conditions=developement",
62
62
  "monorepo:sync_packages_versions": "node ./scripts/monorepo/sync_packages_versions.mjs",
63
63
  "monorepo:publish": "node ./scripts/monorepo/publish_packages.mjs",
@@ -70,23 +70,23 @@
70
70
  "test:snapshot_clear": "npx @jsenv/filesystem clear **/tests/**/side_effects/",
71
71
  "test:ci": "CI=1 npm run test",
72
72
  "test:packages:ci": "CI=1 npm run workspace:test",
73
- "test:only_dev_server_errors": "node --conditions=development ./tests/dev_server/errors/dev_errors_snapshots.test.mjs",
74
- "dev": "node --watch --conditions=development ./scripts/dev/dev.mjs",
75
- "dev:route-inspector": "node --watch --conditions=development ./packages/independent/backend/server/tests/route_inspector/start_server.js",
73
+ "test:only_dev_server_errors": "node --conditions=dev:jsenv ./tests/dev_server/errors/dev_errors_snapshots.test.mjs",
74
+ "dev": "node --watch --conditions=dev:jsenv ./scripts/dev/dev.mjs",
75
+ "dev:route-inspector": "node --watch --conditions=dev:jsenv ./packages/independent/backend/server/tests/route_inspector/start_server.js",
76
76
  "playwright:install": "npx playwright install-deps && npx playwright install",
77
77
  "https:setup": "npx @jsenv/https-local setup",
78
78
  "prepublishOnly": "npm run build"
79
79
  },
80
80
  "dependencies": {
81
81
  "@financial-times/polyfill-useragent-normaliser": "1.10.2",
82
- "@jsenv/ast": "6.6.10",
83
- "@jsenv/js-module-fallback": "1.4.8",
84
- "@jsenv/plugin-bundling": "2.9.4",
85
- "@jsenv/plugin-minification": "1.6.3",
86
- "@jsenv/plugin-supervisor": "1.6.14",
87
- "@jsenv/plugin-transpilation": "1.5.15",
88
- "@jsenv/sourcemap": "1.3.6",
89
- "@jsenv/server": "16.1.1"
82
+ "@jsenv/ast": "6.7.0",
83
+ "@jsenv/js-module-fallback": "1.4.10",
84
+ "@jsenv/plugin-bundling": "2.9.5",
85
+ "@jsenv/plugin-minification": "1.7.0",
86
+ "@jsenv/plugin-supervisor": "1.6.16",
87
+ "@jsenv/plugin-transpilation": "1.5.17",
88
+ "@jsenv/sourcemap": "1.3.7",
89
+ "@jsenv/server": "16.1.2"
90
90
  },
91
91
  "devDependencies": {
92
92
  "@babel/plugin-syntax-decorators": "7.25.9",
@@ -55,6 +55,7 @@ import {
55
55
  urlIsInsideOf,
56
56
  urlToBasename,
57
57
  urlToExtension,
58
+ urlToFilename,
58
59
  urlToRelativeUrl,
59
60
  } from "@jsenv/urls";
60
61
  import { memoryUsage as processMemoryUsage } from "node:process";
@@ -170,7 +171,12 @@ export const build = async ({
170
171
  let runtimeType;
171
172
  {
172
173
  if (isBareSpecifier(key)) {
173
- const packageConditions = ["development", "node", "import"];
174
+ const packageConditions = [
175
+ "development",
176
+ "dev:*",
177
+ "node",
178
+ "import",
179
+ ];
174
180
  try {
175
181
  const { url, type } = applyNodeEsmResolution({
176
182
  conditions: packageConditions,
@@ -347,7 +353,42 @@ export const build = async ({
347
353
  { sourceUrlToLog, buildUrlToLog },
348
354
  ) => {
349
355
  let content = "";
350
- content += `${UNICODE.OK} ${ANSI.color(sourceUrlToLog, ANSI.GREY)} ${ANSI.color("->", ANSI.GREY)} ${ANSI.color(buildUrlToLog, "")}`;
356
+
357
+ const applyColorOnFileRelativeUrl = (fileRelativeUrl, color) => {
358
+ const fileUrl = new URL(fileRelativeUrl, rootPackageDirectoryUrl);
359
+ const packageDirectoryUrl = lookupPackageDirectory(fileUrl);
360
+ if (
361
+ !packageDirectoryUrl ||
362
+ packageDirectoryUrl === rootPackageDirectoryUrl
363
+ ) {
364
+ return ANSI.color(fileRelativeUrl, color);
365
+ }
366
+ const parentDirectoryUrl = new URL("../", packageDirectoryUrl).href;
367
+ const beforePackageDirectoryName = urlToRelativeUrl(
368
+ parentDirectoryUrl,
369
+ rootPackageDirectoryUrl,
370
+ );
371
+ const packageDirectoryName = urlToFilename(packageDirectoryUrl);
372
+ const afterPackageDirectoryUrl = urlToRelativeUrl(
373
+ fileUrl,
374
+ packageDirectoryUrl,
375
+ );
376
+ const beforePackageNameStylized = ANSI.color(
377
+ beforePackageDirectoryName,
378
+ color,
379
+ );
380
+ const packageNameStylized = ANSI.color(
381
+ ANSI.effect(packageDirectoryName, ANSI.UNDERLINE),
382
+ color,
383
+ );
384
+ const afterPackageNameStylized = ANSI.color(
385
+ `/${afterPackageDirectoryUrl}`,
386
+ color,
387
+ );
388
+ return `${beforePackageNameStylized}${packageNameStylized}${afterPackageNameStylized}`;
389
+ };
390
+
391
+ content += `${UNICODE.OK} ${applyColorOnFileRelativeUrl(sourceUrlToLog, ANSI.GREY)} ${ANSI.color("->", ANSI.GREY)} ${applyColorOnFileRelativeUrl(buildUrlToLog, "")}`;
351
392
  // content += " ";
352
393
  // content += ANSI.color("(", ANSI.GREY);
353
394
  // content += ANSI.color(
@@ -853,6 +894,7 @@ const entryPointDefaultParams = {
853
894
  scenarioPlaceholders: undefined,
854
895
  injections: undefined,
855
896
  transpilation: {},
897
+ preserveComments: undefined,
856
898
 
857
899
  versioningMethod: "search_param", // "filename", "search_param"
858
900
  versioningViaImportmap: true,
@@ -904,6 +946,7 @@ const prepareEntryPointBuild = async (
904
946
  scenarioPlaceholders,
905
947
  injections,
906
948
  transpilation,
949
+ preserveComments,
907
950
 
908
951
  versioningMethod,
909
952
  versioningViaImportmap,
@@ -979,6 +1022,9 @@ const prepareEntryPointBuild = async (
979
1022
  if (entryPointParams.assetManifest === undefined) {
980
1023
  assetManifest = versioningMethod === "filename";
981
1024
  }
1025
+ if (entryPointParams.preserveComments === undefined) {
1026
+ preserveComments = someEntryPointUseNode;
1027
+ }
982
1028
  }
983
1029
 
984
1030
  const buildOperation = Abort.startOperation();
@@ -1037,7 +1083,7 @@ const prepareEntryPointBuild = async (
1037
1083
  },
1038
1084
  ...plugins,
1039
1085
  ...(bundling ? [jsenvPluginBundling(bundling)] : []),
1040
- ...(minification ? [jsenvPluginMinification(minification)] : []),
1086
+ jsenvPluginMinification(minification, { preserveComments }),
1041
1087
  ...getCorePlugins({
1042
1088
  packageDirectory,
1043
1089
  rootDirectoryUrl: sourceDirectoryUrl,
@@ -126,28 +126,63 @@ const createBuildPackageConditions = (
126
126
  const nodeRuntimeEnabled = Object.keys(runtimeCompat).includes("node");
127
127
  // https://nodejs.org/api/esm.html#resolver-algorithm-specification
128
128
  const processArgConditions = readCustomConditionsFromProcessArgs();
129
- const packageConditionsDefaultResolvers = {};
130
- for (const processArgCondition of processArgConditions) {
131
- packageConditionsDefaultResolvers[processArgCondition] = true;
132
- }
133
- const packageConditionResolvers = {
134
- ...packageConditionsDefaultResolvers,
135
- development: (specifier, importer) => {
136
- if (isBareSpecifier(specifier)) {
137
- const { url } = applyNodeEsmResolution({
138
- specifier,
139
- parentUrl: importer,
140
- });
141
- return !url.includes("/node_modules/");
129
+ const devResolver = (specifier, importer) => {
130
+ if (isBareSpecifier(specifier)) {
131
+ const { url } = applyNodeEsmResolution({
132
+ specifier,
133
+ parentUrl: importer,
134
+ });
135
+ return !url.includes("/node_modules/");
136
+ }
137
+ return !importer.includes("/node_modules/");
138
+ };
139
+
140
+ const conditionDefaultResolvers = {
141
+ "dev:*": devResolver,
142
+ "development": devResolver,
143
+ "node": nodeRuntimeEnabled,
144
+ "browser": !nodeRuntimeEnabled,
145
+ "import": true,
146
+ };
147
+ const conditionResolvers = {
148
+ ...conditionDefaultResolvers,
149
+ };
150
+
151
+ let wildcardToRemoveSet = new Set();
152
+ const addCustomResolver = (condition, customResolver) => {
153
+ for (const conditionCandidate of Object.keys(conditionDefaultResolvers)) {
154
+ if (conditionCandidate.includes("*")) {
155
+ const conditionRegex = new RegExp(
156
+ `^${conditionCandidate.replace(/\*/g, "(.*)")}$`,
157
+ );
158
+ if (conditionRegex.test(condition)) {
159
+ const existingResolver =
160
+ conditionDefaultResolvers[conditionCandidate];
161
+ wildcardToRemoveSet.add(conditionCandidate);
162
+ conditionResolvers[condition] = combineTwoPackageConditionResolvers(
163
+ existingResolver,
164
+ customResolver,
165
+ );
166
+ return;
167
+ }
142
168
  }
143
- return !importer.includes("/node_modules/");
144
- },
145
- node: nodeRuntimeEnabled,
146
- browser: !nodeRuntimeEnabled,
147
- import: true,
169
+ }
170
+ const existingResolver = conditionDefaultResolvers[condition];
171
+ if (existingResolver) {
172
+ conditionResolvers[condition] = combineTwoPackageConditionResolvers(
173
+ existingResolver,
174
+ customResolver,
175
+ );
176
+ return;
177
+ }
178
+ conditionResolvers[condition] = customResolver;
148
179
  };
149
- for (const condition of Object.keys(packageConditions)) {
150
- const value = packageConditions[condition];
180
+
181
+ for (const processArgCondition of processArgConditions) {
182
+ addCustomResolver(processArgCondition, true);
183
+ }
184
+ for (const customCondition of Object.keys(packageConditions)) {
185
+ const value = packageConditions[customCondition];
151
186
  let customResolver;
152
187
  if (typeof value === "object") {
153
188
  const associations = URL_META.resolveAssociations(
@@ -190,29 +225,25 @@ const createBuildPackageConditions = (
190
225
  } else if (typeof value === "function") {
191
226
  customResolver = value;
192
227
  } else {
193
- customResolver = () => value;
194
- }
195
- const existing = packageConditionResolvers[condition];
196
- if (existing) {
197
- packageConditionResolvers[condition] = (...args) => {
198
- const customResult = customResolver(...args);
199
- return customResult === undefined ? existing(...args) : customResult;
200
- };
201
- } else {
202
- packageConditionResolvers[condition] = customResolver;
228
+ customResolver = value;
203
229
  }
230
+ addCustomResolver(customCondition, customResolver);
204
231
  }
205
232
 
233
+ for (const wildcardToRemove of wildcardToRemoveSet) {
234
+ delete conditionResolvers[wildcardToRemove];
235
+ }
236
+
237
+ const conditionCandidateArray = Object.keys(conditionResolvers);
206
238
  return (specifier, importer) => {
207
239
  const conditions = [];
208
- for (const conditionCandidate of Object.keys(packageConditionResolvers)) {
209
- const packageConditionResolver =
210
- packageConditionResolvers[conditionCandidate];
211
- if (typeof packageConditionResolver === "function") {
212
- if (packageConditionResolver(specifier, importer)) {
240
+ for (const conditionCandidate of conditionCandidateArray) {
241
+ const conditionResolver = conditionResolvers[conditionCandidate];
242
+ if (typeof conditionResolver === "function") {
243
+ if (conditionResolver(specifier, importer)) {
213
244
  conditions.push(conditionCandidate);
214
245
  }
215
- } else if (packageConditionResolver) {
246
+ } else if (conditionResolver) {
216
247
  conditions.push(conditionCandidate);
217
248
  }
218
249
  }
@@ -220,6 +251,22 @@ const createBuildPackageConditions = (
220
251
  };
221
252
  };
222
253
 
254
+ const combineTwoPackageConditionResolvers = (first, second) => {
255
+ if (typeof second !== "function") {
256
+ return second;
257
+ }
258
+ return (...args) => {
259
+ const secondResult = second(...args);
260
+ if (secondResult !== undefined) {
261
+ return secondResult;
262
+ }
263
+ if (typeof first === "function") {
264
+ return first(...args);
265
+ }
266
+ return first;
267
+ };
268
+ };
269
+
223
270
  const addRelationshipWithPackageJson = ({
224
271
  reference,
225
272
  packageJsonUrl,