@jsenv/core 40.12.7 → 40.12.8
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/build/browserslist_index/browserslist_index.js +1 -1
- package/dist/build/build.js +276 -73
- package/dist/build/jsenv_core_packages.js +23 -19
- package/dist/start_dev_server/jsenv_core_packages.js +24 -20
- package/dist/start_dev_server/start_dev_server.js +336 -121
- package/package.json +2 -2
- package/src/build/build.js +8 -9
- package/src/dev/start_dev_server.js +68 -58
- package/src/kitchen/errors.js +8 -0
- package/src/kitchen/package_directory.js +22 -0
- package/src/kitchen/url_graph/url_graph.js +33 -19
- package/src/plugins/plugins.js +11 -4
- package/src/plugins/resolution_node_esm/jsenv_plugin_node_esm_resolution.js +6 -3
- package/src/plugins/resolution_node_esm/node_esm_resolver.js +75 -39
- package/src/plugins/workspace_bundle/jsenv_plugin_workspace_bundle.js +119 -0
package/dist/build/build.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { parseHtml, injectHtmlNodeAsEarlyAsPossible, createHtmlNode, stringifyHtmlAst, applyBabelPlugins, generateUrlForInlineContent, injectJsenvScript, parseJsWithAcorn, visitHtmlNodes, analyzeScriptNode, getHtmlNodeText, getHtmlNodeAttribute, getHtmlNodePosition, getUrlForContentInsideHtml, setHtmlNodeAttributes, setHtmlNodeText, parseCssUrls, getHtmlNodeAttributePosition, parseSrcSet, removeHtmlNodeText, parseJsUrls, getUrlForContentInsideJs, analyzeLinkNode, findHtmlNode, removeHtmlNode, insertHtmlNodeAfter } from "@jsenv/ast";
|
|
2
|
-
import { jsenvPluginBundling } from "@jsenv/plugin-bundling";
|
|
2
|
+
import { bundleJsModules, jsenvPluginBundling } from "@jsenv/plugin-bundling";
|
|
3
3
|
import { jsenvPluginMinification } from "@jsenv/plugin-minification";
|
|
4
4
|
import { jsenvPluginTranspilation, jsenvPluginJsModuleFallback } from "@jsenv/plugin-transpilation";
|
|
5
5
|
import { memoryUsage } from "node:process";
|
|
6
6
|
import { readFileSync, existsSync, readdirSync, lstatSync, realpathSync } from "node:fs";
|
|
7
|
-
import { lookupPackageDirectory, registerDirectoryLifecycle, urlToRelativeUrl, createDetailedMessage, stringifyUrlSite, generateContentFrame, validateResponseIntegrity, urlIsOrIsInsideOf, ensureWindowsDriveLetter, setUrlFilename, moveUrl, getCallerPosition, urlToBasename, urlToExtension, asSpecifierWithoutSearch, asUrlWithoutSearch, injectQueryParamsIntoSpecifier, bufferToEtag, isFileSystemPath, urlToPathname, setUrlBasename, urlToFileSystemPath, writeFileSync, createLogger, URL_META, applyNodeEsmResolution, normalizeUrl, ANSI, RUNTIME_COMPAT, CONTENT_TYPE, urlToFilename, DATA_URL, errorToHTML, normalizeImportMap, composeTwoImportMaps, resolveImport, JS_QUOTES,
|
|
7
|
+
import { lookupPackageDirectory, registerDirectoryLifecycle, urlToRelativeUrl, createDetailedMessage, stringifyUrlSite, generateContentFrame, validateResponseIntegrity, urlIsOrIsInsideOf, ensureWindowsDriveLetter, setUrlFilename, moveUrl, getCallerPosition, urlToBasename, urlToExtension, asSpecifierWithoutSearch, asUrlWithoutSearch, injectQueryParamsIntoSpecifier, bufferToEtag, isFileSystemPath, urlToPathname, setUrlBasename, urlToFileSystemPath, writeFileSync, createLogger, URL_META, applyNodeEsmResolution, normalizeUrl, ANSI, RUNTIME_COMPAT, CONTENT_TYPE, readPackageAtOrNull, urlToFilename, DATA_URL, errorToHTML, normalizeImportMap, composeTwoImportMaps, resolveImport, JS_QUOTES, readCustomConditionsFromProcessArgs, readEntryStatSync, ensurePathnameTrailingSlash, compareFileUrls, applyFileSystemMagicResolution, getExtensionsToTry, setUrlExtension, isSpecifierForNodeBuiltin, injectQueryParams, renderDetails, humanizeDuration, humanizeFileSize, renderTable, renderBigSection, distributePercentages, humanizeMemory, comparePathnames, UNICODE, escapeRegexpSpecialChars, injectQueryParamIntoSpecifierWithoutEncoding, renderUrlOrRelativeUrlFilename, assertAndNormalizeDirectoryUrl, Abort, raceProcessTeardownEvents, startMonitoringCpuUsage, startMonitoringMemoryUsage, inferRuntimeCompatFromClosestPackage, browserDefaultRuntimeCompat, nodeDefaultRuntimeCompat, clearDirectorySync, createTaskLog, createLookupPackageDirectory, ensureEmptyDirectory, updateJsonFileSync, createDynamicLog } from "./jsenv_core_packages.js";
|
|
8
8
|
import { pathToFileURL } from "node:url";
|
|
9
9
|
import { generateSourcemapFileUrl, createMagicSource, composeTwoSourcemaps, generateSourcemapDataUrl, SOURCEMAP } from "@jsenv/sourcemap";
|
|
10
10
|
import { performance } from "node:perf_hooks";
|
|
@@ -468,6 +468,14 @@ const detailsFromPluginController = (pluginController) => {
|
|
|
468
468
|
|
|
469
469
|
const detailsFromValueThrown = (valueThrownByPlugin) => {
|
|
470
470
|
if (valueThrownByPlugin && valueThrownByPlugin instanceof Error) {
|
|
471
|
+
// if (
|
|
472
|
+
// valueThrownByPlugin.message.includes("Maximum call stack size exceeded")
|
|
473
|
+
// ) {
|
|
474
|
+
// return {
|
|
475
|
+
// "error message": valueThrownByPlugin.message,
|
|
476
|
+
// "error stack": valueThrownByPlugin.stack,
|
|
477
|
+
// };
|
|
478
|
+
// }
|
|
471
479
|
if (
|
|
472
480
|
valueThrownByPlugin.code === "PARSE_ERROR" ||
|
|
473
481
|
valueThrownByPlugin.code === "MODULE_NOT_FOUND" ||
|
|
@@ -2007,26 +2015,13 @@ const createUrlInfo = (url, context) => {
|
|
|
2007
2015
|
}
|
|
2008
2016
|
return false;
|
|
2009
2017
|
};
|
|
2010
|
-
|
|
2011
|
-
// The search param can be
|
|
2012
|
-
// 1. injected by a plugin during "redirectReference"
|
|
2013
|
-
// - import assertions
|
|
2014
|
-
// - js module fallback to systemjs
|
|
2015
|
-
// 2. already inside source files
|
|
2016
|
-
// - turn js module into js classic for convenience ?as_js_classic
|
|
2017
|
-
// - turn js classic to js module for to make it importable
|
|
2018
|
-
if (!urlInfo.searchParams.has(searchParam)) {
|
|
2019
|
-
return null;
|
|
2020
|
-
}
|
|
2018
|
+
const getNextUrlInfo = (newProps) => {
|
|
2021
2019
|
const reference = urlInfo.firstReference;
|
|
2022
|
-
const
|
|
2023
|
-
[searchParam]: undefined,
|
|
2024
|
-
});
|
|
2025
|
-
const referenceWithoutSearchParam = reference.addImplicit({
|
|
2020
|
+
const nextReference = reference.addImplicit({
|
|
2026
2021
|
type: reference.type,
|
|
2027
2022
|
subtype: reference.subtype,
|
|
2028
2023
|
expectedContentType: reference.expectedContentType,
|
|
2029
|
-
expectedType:
|
|
2024
|
+
expectedType: reference.expectedType,
|
|
2030
2025
|
expectedSubtype: reference.expectedSubtype,
|
|
2031
2026
|
integrity: reference.integrity,
|
|
2032
2027
|
crossorigin: reference.crossorigin,
|
|
@@ -2050,7 +2045,6 @@ const createUrlInfo = (url, context) => {
|
|
|
2050
2045
|
astInfo: reference.astInfo,
|
|
2051
2046
|
mutation: reference.mutation,
|
|
2052
2047
|
data: { ...reference.data },
|
|
2053
|
-
specifier: newSpecifier,
|
|
2054
2048
|
isWeak: true,
|
|
2055
2049
|
isInline: reference.isInline,
|
|
2056
2050
|
original: reference.original || reference,
|
|
@@ -2060,9 +2054,37 @@ const createUrlInfo = (url, context) => {
|
|
|
2060
2054
|
// generatedUrl: null,
|
|
2061
2055
|
// generatedSpecifier: null,
|
|
2062
2056
|
// filename: null,
|
|
2057
|
+
...newProps,
|
|
2058
|
+
});
|
|
2059
|
+
reference.next = nextReference;
|
|
2060
|
+
return nextReference.urlInfo;
|
|
2061
|
+
};
|
|
2062
|
+
|
|
2063
|
+
urlInfo.redirect = (props) => {
|
|
2064
|
+
return getNextUrlInfo(props);
|
|
2065
|
+
};
|
|
2066
|
+
urlInfo.getWithoutSearchParam = (searchParam, props) => {
|
|
2067
|
+
// The search param can be
|
|
2068
|
+
// 1. injected by a plugin during "redirectReference"
|
|
2069
|
+
// - import assertions
|
|
2070
|
+
// - js module fallback to systemjs
|
|
2071
|
+
// 2. already inside source files
|
|
2072
|
+
// - turn js module into js classic for convenience ?as_js_classic
|
|
2073
|
+
// - turn js classic to js module for to make it importable
|
|
2074
|
+
if (!urlInfo.searchParams.has(searchParam)) {
|
|
2075
|
+
return null;
|
|
2076
|
+
}
|
|
2077
|
+
const reference = urlInfo.firstReference;
|
|
2078
|
+
const specifierWithoutSearchParam = injectQueryParamsIntoSpecifier(
|
|
2079
|
+
reference.specifier,
|
|
2080
|
+
{
|
|
2081
|
+
[searchParam]: undefined,
|
|
2082
|
+
},
|
|
2083
|
+
);
|
|
2084
|
+
return urlInfo.redirect({
|
|
2085
|
+
specifier: specifierWithoutSearchParam,
|
|
2086
|
+
...props,
|
|
2063
2087
|
});
|
|
2064
|
-
reference.next = referenceWithoutSearchParam;
|
|
2065
|
-
return referenceWithoutSearchParam.urlInfo;
|
|
2066
2088
|
};
|
|
2067
2089
|
urlInfo.onRemoved = () => {
|
|
2068
2090
|
urlInfo.kitchen.urlInfoTransformer.resetContent(urlInfo);
|
|
@@ -3764,6 +3786,24 @@ const inferUrlInfoType = (urlInfo) => {
|
|
|
3764
3786
|
return expectedType || "other";
|
|
3765
3787
|
};
|
|
3766
3788
|
|
|
3789
|
+
const createPackageDirectory = ({
|
|
3790
|
+
sourceDirectoryUrl,
|
|
3791
|
+
lookupPackageDirectory: lookupPackageDirectory$1 = lookupPackageDirectory,
|
|
3792
|
+
}) => {
|
|
3793
|
+
const packageDirectory = {
|
|
3794
|
+
url: lookupPackageDirectory$1(sourceDirectoryUrl),
|
|
3795
|
+
find: (url) => {
|
|
3796
|
+
const urlString = typeof url === "string" ? url : url?.href;
|
|
3797
|
+
if (!urlString.startsWith("file:")) {
|
|
3798
|
+
return null;
|
|
3799
|
+
}
|
|
3800
|
+
return lookupPackageDirectory$1(url);
|
|
3801
|
+
},
|
|
3802
|
+
read: readPackageAtOrNull,
|
|
3803
|
+
};
|
|
3804
|
+
return packageDirectory;
|
|
3805
|
+
};
|
|
3806
|
+
|
|
3767
3807
|
const jsenvPluginDirectoryReferenceEffect = (
|
|
3768
3808
|
directoryReferenceEffect = "error",
|
|
3769
3809
|
{ rootDirectoryUrl },
|
|
@@ -5884,18 +5924,27 @@ const jsenvPluginInlineContentFetcher = () => {
|
|
|
5884
5924
|
|
|
5885
5925
|
|
|
5886
5926
|
const createNodeEsmResolver = ({
|
|
5927
|
+
packageDirectory,
|
|
5887
5928
|
runtimeCompat,
|
|
5888
5929
|
rootDirectoryUrl,
|
|
5889
5930
|
packageConditions = {},
|
|
5890
5931
|
packageConditionsConfig,
|
|
5891
5932
|
preservesSymlink,
|
|
5892
5933
|
}) => {
|
|
5934
|
+
const applyNodeEsmResolutionMemo = (params) =>
|
|
5935
|
+
applyNodeEsmResolution({
|
|
5936
|
+
lookupPackageScope: packageDirectory.find,
|
|
5937
|
+
readPackageJson: packageDirectory.read,
|
|
5938
|
+
preservesSymlink,
|
|
5939
|
+
...params,
|
|
5940
|
+
});
|
|
5893
5941
|
const buildPackageConditions = createBuildPackageConditions(
|
|
5894
5942
|
packageConditions,
|
|
5895
5943
|
{
|
|
5896
5944
|
packageConditionsConfig,
|
|
5897
5945
|
rootDirectoryUrl,
|
|
5898
5946
|
runtimeCompat,
|
|
5947
|
+
preservesSymlink,
|
|
5899
5948
|
},
|
|
5900
5949
|
);
|
|
5901
5950
|
|
|
@@ -5927,7 +5976,7 @@ const createNodeEsmResolver = ({
|
|
|
5927
5976
|
reference.type === "sourcemap_comment";
|
|
5928
5977
|
|
|
5929
5978
|
const resolveNodeEsmFallbackOnWeb = createResolverWithFallbackOnError(
|
|
5930
|
-
|
|
5979
|
+
applyNodeEsmResolutionMemo,
|
|
5931
5980
|
({ specifier, parentUrl }) => {
|
|
5932
5981
|
const url = new URL(specifier, parentUrl).href;
|
|
5933
5982
|
return { url };
|
|
@@ -5936,7 +5985,7 @@ const createNodeEsmResolver = ({
|
|
|
5936
5985
|
const DELEGATE_TO_WEB_RESOLUTION_PLUGIN = {};
|
|
5937
5986
|
const resolveNodeEsmFallbackNullToDelegateToWebPlugin =
|
|
5938
5987
|
createResolverWithFallbackOnError(
|
|
5939
|
-
|
|
5988
|
+
applyNodeEsmResolutionMemo,
|
|
5940
5989
|
() => DELEGATE_TO_WEB_RESOLUTION_PLUGIN,
|
|
5941
5990
|
);
|
|
5942
5991
|
|
|
@@ -5944,11 +5993,11 @@ const createNodeEsmResolver = ({
|
|
|
5944
5993
|
webResolutionFallback,
|
|
5945
5994
|
resolver: webResolutionFallback
|
|
5946
5995
|
? resolveNodeEsmFallbackOnWeb
|
|
5947
|
-
:
|
|
5996
|
+
: applyNodeEsmResolutionMemo,
|
|
5948
5997
|
});
|
|
5949
5998
|
const resolver = webResolutionFallback
|
|
5950
5999
|
? resolveNodeEsmFallbackNullToDelegateToWebPlugin
|
|
5951
|
-
:
|
|
6000
|
+
: applyNodeEsmResolutionMemo;
|
|
5952
6001
|
|
|
5953
6002
|
const result = resolver({
|
|
5954
6003
|
conditions,
|
|
@@ -5979,52 +6028,79 @@ const createNodeEsmResolver = ({
|
|
|
5979
6028
|
if (ownerUrlInfo.context.build) {
|
|
5980
6029
|
return url;
|
|
5981
6030
|
}
|
|
5982
|
-
|
|
5983
|
-
|
|
5984
|
-
|
|
5985
|
-
|
|
5986
|
-
|
|
5987
|
-
|
|
5988
|
-
|
|
5989
|
-
//
|
|
5990
|
-
|
|
5991
|
-
|
|
5992
|
-
|
|
5993
|
-
|
|
5994
|
-
|
|
5995
|
-
|
|
5996
|
-
|
|
5997
|
-
|
|
5998
|
-
|
|
5999
|
-
|
|
6000
|
-
|
|
6001
|
-
|
|
6002
|
-
|
|
6003
|
-
|
|
6004
|
-
|
|
6005
|
-
packageDirectoryUrl !== ownerUrlInfo.context.rootDirectoryUrl
|
|
6006
|
-
) {
|
|
6007
|
-
const packageVersion =
|
|
6008
|
-
defaultReadPackageJson(packageDirectoryUrl).version;
|
|
6009
|
-
// package version can be null, see https://github.com/babel/babel/blob/2ce56e832c2dd7a7ed92c89028ba929f874c2f5c/packages/babel-runtime/helpers/esm/package.json#L2
|
|
6010
|
-
if (packageVersion) {
|
|
6031
|
+
|
|
6032
|
+
package_relationships: {
|
|
6033
|
+
if (!url.startsWith("file:")) {
|
|
6034
|
+
// data:, javascript:void(0), etc...
|
|
6035
|
+
break package_relationships;
|
|
6036
|
+
}
|
|
6037
|
+
|
|
6038
|
+
// packageDirectoryUrl can be already known thanks to node resolution
|
|
6039
|
+
// otherwise we look for it
|
|
6040
|
+
const closestPackageDirectoryUrl =
|
|
6041
|
+
packageDirectoryUrl || packageDirectory.find(url);
|
|
6042
|
+
if (!closestPackageDirectoryUrl) {
|
|
6043
|
+
// happens for projects without package.json or some files outside of package scope
|
|
6044
|
+
// (generated files like sourcemaps or cache files for example)
|
|
6045
|
+
break package_relationships;
|
|
6046
|
+
}
|
|
6047
|
+
|
|
6048
|
+
{
|
|
6049
|
+
const dependsOnPackageJson = Boolean(packageDirectoryUrl);
|
|
6050
|
+
if (dependsOnPackageJson) {
|
|
6051
|
+
// this reference depends on package.json and node_modules
|
|
6052
|
+
// to be resolved. Each file using this specifier
|
|
6053
|
+
// must be invalidated when corresponding package.json changes
|
|
6011
6054
|
addRelationshipWithPackageJson({
|
|
6012
6055
|
reference,
|
|
6013
6056
|
packageJsonUrl: `${packageDirectoryUrl}package.json`,
|
|
6014
|
-
field: "
|
|
6015
|
-
|
|
6057
|
+
field: type.startsWith("field:")
|
|
6058
|
+
? `#${type.slice("field:".length)}`
|
|
6059
|
+
: "",
|
|
6016
6060
|
});
|
|
6017
6061
|
}
|
|
6018
|
-
|
|
6062
|
+
}
|
|
6063
|
+
version_relationship: {
|
|
6064
|
+
const packageVersion = packageDirectory.read(
|
|
6065
|
+
closestPackageDirectoryUrl,
|
|
6066
|
+
).version;
|
|
6067
|
+
if (!packageVersion) {
|
|
6068
|
+
// package version can be null, see https://github.com/babel/babel/blob/2ce56e832c2dd7a7ed92c89028ba929f874c2f5c/packages/babel-runtime/helpers/esm/package.json#L2
|
|
6069
|
+
break version_relationship;
|
|
6070
|
+
}
|
|
6071
|
+
// We want the versioning effect
|
|
6072
|
+
// which would put the file in browser cache for 1 year based on that version
|
|
6073
|
+
// only for files we don't control and touch ourselves (node modules)
|
|
6074
|
+
// which would never change until their version change
|
|
6075
|
+
// (minus the case you update them yourselves in your node modules without updating the package version)
|
|
6076
|
+
// (in that case you would have to clear browser cache to use the modified version of the node module files)
|
|
6077
|
+
const hasVersioningEffect =
|
|
6078
|
+
closestPackageDirectoryUrl !== packageDirectory.url &&
|
|
6079
|
+
url.includes("/node_modules/");
|
|
6080
|
+
addRelationshipWithPackageJson({
|
|
6081
|
+
reference,
|
|
6082
|
+
packageJsonUrl: `${closestPackageDirectoryUrl}package.json`,
|
|
6083
|
+
field: "version",
|
|
6084
|
+
hasVersioningEffect,
|
|
6085
|
+
});
|
|
6086
|
+
if (hasVersioningEffect) {
|
|
6087
|
+
reference.version = packageVersion;
|
|
6088
|
+
}
|
|
6019
6089
|
}
|
|
6020
6090
|
}
|
|
6091
|
+
|
|
6021
6092
|
return url;
|
|
6022
6093
|
};
|
|
6023
6094
|
};
|
|
6024
6095
|
|
|
6025
6096
|
const createBuildPackageConditions = (
|
|
6026
6097
|
packageConditions,
|
|
6027
|
-
{
|
|
6098
|
+
{
|
|
6099
|
+
packageConditionsConfig,
|
|
6100
|
+
rootDirectoryUrl,
|
|
6101
|
+
runtimeCompat,
|
|
6102
|
+
preservesSymlink,
|
|
6103
|
+
},
|
|
6028
6104
|
) => {
|
|
6029
6105
|
let resolveConditionsFromSpecifier = () => null;
|
|
6030
6106
|
let resolveConditionsFromContext = () => [];
|
|
@@ -6051,6 +6127,7 @@ const createBuildPackageConditions = (
|
|
|
6051
6127
|
const { packageDirectoryUrl } = applyNodeEsmResolution({
|
|
6052
6128
|
specifier: key.slice(0, -1), // avoid package path not exported
|
|
6053
6129
|
parentUrl: rootDirectoryUrl,
|
|
6130
|
+
preservesSymlink,
|
|
6054
6131
|
});
|
|
6055
6132
|
const url = packageDirectoryUrl;
|
|
6056
6133
|
associationsRaw[url] = associatedValue;
|
|
@@ -6059,6 +6136,7 @@ const createBuildPackageConditions = (
|
|
|
6059
6136
|
const { url } = applyNodeEsmResolution({
|
|
6060
6137
|
specifier: key,
|
|
6061
6138
|
parentUrl: rootDirectoryUrl,
|
|
6139
|
+
preservesSymlink,
|
|
6062
6140
|
});
|
|
6063
6141
|
associationsRaw[url] = associatedValue;
|
|
6064
6142
|
} catch {
|
|
@@ -6330,11 +6408,12 @@ const isBareSpecifier$1 = (specifier) => {
|
|
|
6330
6408
|
}
|
|
6331
6409
|
};
|
|
6332
6410
|
|
|
6333
|
-
const jsenvPluginNodeEsmResolution = (
|
|
6411
|
+
const jsenvPluginNodeEsmResolution = ({
|
|
6412
|
+
packageDirectory,
|
|
6334
6413
|
resolutionConfig = {},
|
|
6335
6414
|
packageConditions,
|
|
6336
6415
|
packageConditionsConfig = {},
|
|
6337
|
-
) => {
|
|
6416
|
+
}) => {
|
|
6338
6417
|
let nodeEsmResolverDefault;
|
|
6339
6418
|
const resolverMap = new Map();
|
|
6340
6419
|
let anyTypeResolver;
|
|
@@ -6352,6 +6431,7 @@ const jsenvPluginNodeEsmResolution = (
|
|
|
6352
6431
|
);
|
|
6353
6432
|
}
|
|
6354
6433
|
return createNodeEsmResolver({
|
|
6434
|
+
packageDirectory,
|
|
6355
6435
|
runtimeCompat: kitchenContext.runtimeCompat,
|
|
6356
6436
|
rootDirectoryUrl: kitchenContext.rootDirectoryUrl,
|
|
6357
6437
|
packageConditions,
|
|
@@ -6368,9 +6448,10 @@ const jsenvPluginNodeEsmResolution = (
|
|
|
6368
6448
|
appliesDuring: "*",
|
|
6369
6449
|
init: (kitchenContext) => {
|
|
6370
6450
|
nodeEsmResolverDefault = createNodeEsmResolver({
|
|
6451
|
+
packageDirectory,
|
|
6371
6452
|
runtimeCompat: kitchenContext.runtimeCompat,
|
|
6372
6453
|
rootDirectoryUrl: kitchenContext.rootDirectoryUrl,
|
|
6373
|
-
preservesSymlink: true,
|
|
6454
|
+
// preservesSymlink: true,
|
|
6374
6455
|
packageConditions,
|
|
6375
6456
|
packageConditionsConfig: {
|
|
6376
6457
|
...kitchenContext.packageConditionsConfig,
|
|
@@ -9150,6 +9231,123 @@ const jsenvPluginPackageSideEffects = ({ packageDirectory }) => {
|
|
|
9150
9231
|
};
|
|
9151
9232
|
};
|
|
9152
9233
|
|
|
9234
|
+
const PACKAGE_BUNDLE_QUERY_PARAM = "package_bundle";
|
|
9235
|
+
const PACKAGE_NO_BUNDLE_QUERY_PARAM = "package_no_bundle";
|
|
9236
|
+
const DYNAMIC_IMPORT_QUERY_PARAM = "dynamic_import";
|
|
9237
|
+
|
|
9238
|
+
const jsenvPluginWorkspaceBundle = ({ packageDirectory }) => {
|
|
9239
|
+
return {
|
|
9240
|
+
name: "jsenv:workspace_bundle",
|
|
9241
|
+
appliesDuring: "dev",
|
|
9242
|
+
redirectReference: (reference) => {
|
|
9243
|
+
if (!reference.url.startsWith("file:")) {
|
|
9244
|
+
return null;
|
|
9245
|
+
}
|
|
9246
|
+
if (reference.searchParams.has(PACKAGE_BUNDLE_QUERY_PARAM)) {
|
|
9247
|
+
return null;
|
|
9248
|
+
}
|
|
9249
|
+
if (reference.searchParams.has(PACKAGE_NO_BUNDLE_QUERY_PARAM)) {
|
|
9250
|
+
return null;
|
|
9251
|
+
}
|
|
9252
|
+
if (
|
|
9253
|
+
reference.ownerUrlInfo.searchParams.has(PACKAGE_NO_BUNDLE_QUERY_PARAM)
|
|
9254
|
+
) {
|
|
9255
|
+
// we're cooking the bundle, without this check we would have infinite recursion to try to bundle
|
|
9256
|
+
// we want to propagate the ?package_no_bundle
|
|
9257
|
+
const noBundleUrl = injectQueryParams(reference.url, {
|
|
9258
|
+
v: undefined,
|
|
9259
|
+
[PACKAGE_NO_BUNDLE_QUERY_PARAM]: "",
|
|
9260
|
+
});
|
|
9261
|
+
// console.log(
|
|
9262
|
+
// `redirecting ${reference.url} to ${noBundleUrl} to cook the bundle`,
|
|
9263
|
+
// );
|
|
9264
|
+
return noBundleUrl;
|
|
9265
|
+
}
|
|
9266
|
+
const packageDirectoryUrl = packageDirectory.find(reference.url);
|
|
9267
|
+
if (!packageDirectoryUrl) {
|
|
9268
|
+
return null;
|
|
9269
|
+
}
|
|
9270
|
+
if (packageDirectoryUrl === packageDirectory.url) {
|
|
9271
|
+
// root package, we don't want to bundle
|
|
9272
|
+
return null;
|
|
9273
|
+
}
|
|
9274
|
+
// we make sure we target the bundle version of the package
|
|
9275
|
+
// otherwise we might execute some parts of the package code multiple times.
|
|
9276
|
+
// so we need to redirect the potential reference to non entry point to the package main entry point
|
|
9277
|
+
const packageJSON = packageDirectory.read(packageDirectoryUrl);
|
|
9278
|
+
const rootReference = reference.ownerUrlInfo.dependencies.inject({
|
|
9279
|
+
type: "js_import",
|
|
9280
|
+
specifier: `${packageJSON.name}?${PACKAGE_BUNDLE_QUERY_PARAM}`,
|
|
9281
|
+
});
|
|
9282
|
+
// console.log(
|
|
9283
|
+
// `redirecting ${reference.url} to ${rootReference.url} to target the package bundle version of the package`,
|
|
9284
|
+
// );
|
|
9285
|
+
const packageMainUrl = rootReference.url;
|
|
9286
|
+
return packageMainUrl;
|
|
9287
|
+
},
|
|
9288
|
+
fetchUrlContent: async (urlInfo) => {
|
|
9289
|
+
if (!urlInfo.searchParams.has(PACKAGE_BUNDLE_QUERY_PARAM)) {
|
|
9290
|
+
return null;
|
|
9291
|
+
}
|
|
9292
|
+
const noBundleSpecifier = injectQueryParamsIntoSpecifier(
|
|
9293
|
+
urlInfo.firstReference.specifier,
|
|
9294
|
+
{
|
|
9295
|
+
[PACKAGE_BUNDLE_QUERY_PARAM]: undefined,
|
|
9296
|
+
[PACKAGE_NO_BUNDLE_QUERY_PARAM]: "",
|
|
9297
|
+
},
|
|
9298
|
+
);
|
|
9299
|
+
const noBundleUrlInfo = urlInfo.redirect({
|
|
9300
|
+
specifier: noBundleSpecifier,
|
|
9301
|
+
});
|
|
9302
|
+
if (!noBundleUrlInfo) {
|
|
9303
|
+
return null;
|
|
9304
|
+
}
|
|
9305
|
+
await noBundleUrlInfo.cook();
|
|
9306
|
+
await noBundleUrlInfo.cookDependencies({
|
|
9307
|
+
// we ignore dynamic import to cook lazyly (as browser request the server)
|
|
9308
|
+
// these dynamic imports must inherit "?package_bundle"
|
|
9309
|
+
// This is done inside rollup for convenience
|
|
9310
|
+
ignoreDynamicImport: true,
|
|
9311
|
+
});
|
|
9312
|
+
const bundleUrlInfos = await bundleJsModules([noBundleUrlInfo], {
|
|
9313
|
+
chunks: false,
|
|
9314
|
+
buildDirectoryUrl: new URL("../src/plugins/workspace_bundle/", import.meta.url),
|
|
9315
|
+
preserveDynamicImports: true,
|
|
9316
|
+
augmentDynamicImportUrlSearchParams: () => {
|
|
9317
|
+
return {
|
|
9318
|
+
[DYNAMIC_IMPORT_QUERY_PARAM]: "",
|
|
9319
|
+
[PACKAGE_BUNDLE_QUERY_PARAM]: "",
|
|
9320
|
+
};
|
|
9321
|
+
},
|
|
9322
|
+
});
|
|
9323
|
+
const bundledUrlInfo = bundleUrlInfos[noBundleUrlInfo.url];
|
|
9324
|
+
if (urlInfo.context.dev) {
|
|
9325
|
+
for (const sourceUrl of bundledUrlInfo.sourceUrls) {
|
|
9326
|
+
urlInfo.dependencies.inject({
|
|
9327
|
+
isImplicit: true,
|
|
9328
|
+
type: "js_url",
|
|
9329
|
+
specifier: sourceUrl,
|
|
9330
|
+
});
|
|
9331
|
+
}
|
|
9332
|
+
}
|
|
9333
|
+
return {
|
|
9334
|
+
content: bundledUrlInfo.content,
|
|
9335
|
+
contentType: "text/javascript",
|
|
9336
|
+
type: "js_module",
|
|
9337
|
+
originalUrl: urlInfo.originalUrl,
|
|
9338
|
+
originalContent: bundledUrlInfo.originalContent,
|
|
9339
|
+
sourcemap: bundledUrlInfo.sourcemap,
|
|
9340
|
+
data: bundledUrlInfo.data,
|
|
9341
|
+
};
|
|
9342
|
+
},
|
|
9343
|
+
// transformReferenceSearchParams: () => {
|
|
9344
|
+
// return {
|
|
9345
|
+
// [PACKAGE_BUNDLE_QUERY_PARAM]: undefined,
|
|
9346
|
+
// };
|
|
9347
|
+
// },
|
|
9348
|
+
};
|
|
9349
|
+
};
|
|
9350
|
+
|
|
9153
9351
|
// tslint:disable:ordered-imports
|
|
9154
9352
|
|
|
9155
9353
|
|
|
@@ -9174,12 +9372,14 @@ const getCorePlugins = ({
|
|
|
9174
9372
|
inlining = true,
|
|
9175
9373
|
http = false,
|
|
9176
9374
|
spa,
|
|
9375
|
+
packageBundle,
|
|
9177
9376
|
|
|
9178
9377
|
clientAutoreload,
|
|
9179
9378
|
clientAutoreloadOnServerRestart,
|
|
9180
9379
|
cacheControl,
|
|
9181
9380
|
scenarioPlaceholders = true,
|
|
9182
9381
|
ribbon = true,
|
|
9382
|
+
dropToOpen = true,
|
|
9183
9383
|
packageSideEffects = false,
|
|
9184
9384
|
} = {}) => {
|
|
9185
9385
|
if (cacheControl === true) {
|
|
@@ -9202,6 +9402,9 @@ const getCorePlugins = ({
|
|
|
9202
9402
|
}
|
|
9203
9403
|
|
|
9204
9404
|
return [
|
|
9405
|
+
...(packageBundle
|
|
9406
|
+
? [jsenvPluginWorkspaceBundle({ packageDirectory })]
|
|
9407
|
+
: []),
|
|
9205
9408
|
jsenvPluginReferenceAnalysis(referenceAnalysis),
|
|
9206
9409
|
jsenvPluginInjections(injections),
|
|
9207
9410
|
jsenvPluginTranspilation(transpilation),
|
|
@@ -9240,11 +9443,12 @@ const getCorePlugins = ({
|
|
|
9240
9443
|
},
|
|
9241
9444
|
...(nodeEsmResolution
|
|
9242
9445
|
? [
|
|
9243
|
-
jsenvPluginNodeEsmResolution(
|
|
9244
|
-
|
|
9446
|
+
jsenvPluginNodeEsmResolution({
|
|
9447
|
+
packageDirectory,
|
|
9448
|
+
resolutionConfig: nodeEsmResolution,
|
|
9245
9449
|
packageConditions,
|
|
9246
9450
|
packageConditionsConfig,
|
|
9247
|
-
),
|
|
9451
|
+
}),
|
|
9248
9452
|
]
|
|
9249
9453
|
: []),
|
|
9250
9454
|
jsenvPluginWebResolution(),
|
|
@@ -9271,7 +9475,7 @@ const getCorePlugins = ({
|
|
|
9271
9475
|
: []),
|
|
9272
9476
|
...(cacheControl ? [jsenvPluginCacheControl(cacheControl)] : []),
|
|
9273
9477
|
...(ribbon ? [jsenvPluginRibbon({ rootDirectoryUrl, ...ribbon })] : []),
|
|
9274
|
-
jsenvPluginDropToOpen(),
|
|
9478
|
+
...(dropToOpen ? [jsenvPluginDropToOpen()] : []),
|
|
9275
9479
|
jsenvPluginCleanHTML(),
|
|
9276
9480
|
jsenvPluginChromeDevtoolsJson(),
|
|
9277
9481
|
...(packageSideEffects
|
|
@@ -11816,20 +12020,19 @@ const build = async ({
|
|
|
11816
12020
|
return compareFileUrls(a.sourceUrl, b.sourceUrl);
|
|
11817
12021
|
});
|
|
11818
12022
|
|
|
11819
|
-
const
|
|
12023
|
+
const lookupPackageDirectory = createLookupPackageDirectory();
|
|
12024
|
+
const packageDirectory = createPackageDirectory({
|
|
12025
|
+
sourceDirectoryUrl,
|
|
12026
|
+
lookupPackageDirectory,
|
|
12027
|
+
});
|
|
11820
12028
|
const packageDirectoryCache = new Map();
|
|
11821
|
-
|
|
12029
|
+
packageDirectory.read = (url) => {
|
|
11822
12030
|
const fromCache = packageDirectoryCache.get(url);
|
|
11823
12031
|
if (fromCache !== undefined) {
|
|
11824
12032
|
return fromCache;
|
|
11825
12033
|
}
|
|
11826
12034
|
return readPackageAtOrNull(url);
|
|
11827
12035
|
};
|
|
11828
|
-
const packageDirectory = {
|
|
11829
|
-
url: lookupPackageDirectory(sourceDirectoryUrl),
|
|
11830
|
-
find: lookupPackageDirectoryUrl,
|
|
11831
|
-
read: readPackageDirectory,
|
|
11832
|
-
};
|
|
11833
12036
|
|
|
11834
12037
|
if (outDirectoryUrl === undefined) {
|
|
11835
12038
|
if (
|
|
@@ -12025,7 +12228,7 @@ const build = async ({
|
|
|
12025
12228
|
sideEffects: sideEffectRelativeUrlArray,
|
|
12026
12229
|
});
|
|
12027
12230
|
};
|
|
12028
|
-
const sideEffects =
|
|
12231
|
+
const sideEffects = packageDirectory.read(
|
|
12029
12232
|
packageDirectory.url,
|
|
12030
12233
|
)?.sideEffects;
|
|
12031
12234
|
if (sideEffects === false) {
|