From 04f3276afa39c79438cf9b3a6ded9420c64b134b Mon Sep 17 00:00:00 2001 From: Damien Maillard Date: Sat, 6 Mar 2021 14:39:17 +0100 Subject: [PATCH 01/36] prepare using codebase to generate importmap as well --- package.json | 4 +- .../generate-import-map.js | 2 + src/getImportMapFromNodeModules.js | 574 +----------------- .../codebase/parseSpecifiersFromFile.js | 99 +++ .../applyPackageManualOverride.js | 0 .../package/getImportMapFromPackages.js | 541 +++++++++++++++++ .../{ => package}/node-module-resolution.js | 2 +- src/internal/{ => package}/readPackageFile.js | 0 src/internal/{ => package}/resolveFile.js | 0 .../{ => package}/resolveNodeModule.js | 0 .../{ => package}/resolvePackageMain.js | 0 .../{ => package}/specifierIsRelative.js | 0 .../{ => package}/visitPackageExports.js | 0 .../{ => package}/visitPackageImports.js | 0 14 files changed, 678 insertions(+), 544 deletions(-) create mode 100644 src/internal/codebase/parseSpecifiersFromFile.js rename src/internal/{ => package}/applyPackageManualOverride.js (100%) create mode 100644 src/internal/package/getImportMapFromPackages.js rename src/internal/{ => package}/node-module-resolution.js (96%) rename src/internal/{ => package}/readPackageFile.js (100%) rename src/internal/{ => package}/resolveFile.js (100%) rename src/internal/{ => package}/resolveNodeModule.js (100%) rename src/internal/{ => package}/resolvePackageMain.js (100%) rename src/internal/{ => package}/specifierIsRelative.js (100%) rename src/internal/{ => package}/visitPackageExports.js (100%) rename src/internal/{ => package}/visitPackageImports.js (100%) diff --git a/package.json b/package.json index 178ad189..1a5891a4 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@jsenv/node-module-import-map", - "version": "12.4.1", + "version": "13.0.0", "description": "Generate importmap for node_modules.", "license": "MIT", "repository": { @@ -43,6 +43,8 @@ "postpublish": "node ./script/transform-package/restore-postinstall.js" }, "dependencies": { + "@babel/parser": "7.13.9", + "@babel/traverse": "7.13.0", "@jsenv/cancellation": "2.0.3", "@jsenv/import-map": "6.11.1", "@jsenv/logger": "4.0.0", diff --git a/script/generate-import-map/generate-import-map.js b/script/generate-import-map/generate-import-map.js index db693b16..20c5cacd 100644 --- a/script/generate-import-map/generate-import-map.js +++ b/script/generate-import-map/generate-import-map.js @@ -8,6 +8,8 @@ generateImportMapForProject( [ getImportMapFromNodeModules({ projectDirectoryUrl, + target: "node", + dev: true, }), ], { diff --git a/src/getImportMapFromNodeModules.js b/src/getImportMapFromNodeModules.js index a4e6f42c..a6fcbfdd 100644 --- a/src/getImportMapFromNodeModules.js +++ b/src/getImportMapFromNodeModules.js @@ -1,558 +1,48 @@ -import { createLogger, createDetailedMessage } from "@jsenv/logger" +import { resolveUrl } from "@jsenv/util" import { moveImportMap, sortImportMap } from "@jsenv/import-map" -import { - resolveUrl, - urlToRelativeUrl, - assertAndNormalizeDirectoryUrl, - urlToFileSystemPath, - urlToBasename, - readFile, -} from "@jsenv/util" -import { resolvePackageMain } from "./internal/resolvePackageMain.js" -import { visitPackageImports } from "./internal/visitPackageImports.js" -import { visitPackageExports } from "./internal/visitPackageExports.js" -import { createFindNodeModulePackage } from "./internal/node-module-resolution.js" +import { getImportMapFromPackages } from "./internal/package/getImportMapFromPackages.js" export const getImportMapFromNodeModules = async ({ - // nothing is actually listening for this cancellationToken for now - // it's not very important but it would be better to register on it - // an stops what we are doing if asked to do so - // cancellationToken = createCancellationTokenForProcess(), logLevel, projectDirectoryUrl, - rootProjectDirectoryUrl, - importMapFileRelativeUrl = "./import-map.importmap", - - projectPackageDevDependenciesIncluded = process.env.NODE_ENV !== "production", - packagesExportsPreference = ["import", "browser"], - packagesExportsIncluded = true, - packagesSelfReference = true, - packagesImportsIncluded = true, - packagesManualOverrides = {}, - packageIncludedPredicate = () => true, + importMapFileRelativeUrl, + target = "browser", + dev = false, + ...rest }) => { - const logger = createLogger({ logLevel }) - - projectDirectoryUrl = assertAndNormalizeDirectoryUrl(projectDirectoryUrl) - if (typeof rootProjectDirectoryUrl === "undefined") { - rootProjectDirectoryUrl = projectDirectoryUrl - } else { - rootProjectDirectoryUrl = assertAndNormalizeDirectoryUrl(rootProjectDirectoryUrl) - } - - const projectPackageFileUrl = resolveUrl("./package.json", projectDirectoryUrl) - const rootProjectPackageFileUrl = resolveUrl("./package.json", rootProjectDirectoryUrl) - const findNodeModulePackage = createFindNodeModulePackage(packagesManualOverrides) - - const imports = {} - const scopes = {} - const seen = {} - - const markPackageAsSeen = (packageFileUrl, importerPackageFileUrl) => { - if (packageFileUrl in seen) { - seen[packageFileUrl].push(importerPackageFileUrl) - } else { - seen[packageFileUrl] = [importerPackageFileUrl] - } - } - - const packageIsSeen = (packageFileUrl, importerPackageFileUrl) => { - return packageFileUrl in seen && seen[packageFileUrl].includes(importerPackageFileUrl) - } - - const visit = async ({ - packageFileUrl, - packageName, - packageJsonObject, - importerPackageFileUrl, - importerPackageJsonObject, - includeDevDependencies, - }) => { - if (!packageIncludedPredicate({ packageName, packageFileUrl, packageJsonObject })) { - return - } - - await visitDependencies({ - packageFileUrl, - packageJsonObject, - includeDevDependencies, - }) - await visitPackage({ - packageFileUrl, - packageName, - packageJsonObject, - importerPackageFileUrl, - importerPackageJsonObject, - }) - } - - const visitPackage = async ({ - packageFileUrl, - packageName, - packageJsonObject, - importerPackageFileUrl, - importerPackageJsonObject, - }) => { - const packageInfo = computePackageInfo({ - packageFileUrl, - packageName, - importerPackageFileUrl, - }) - - await visitPackageMain({ - packageFileUrl, - packageName, - packageJsonObject, - packageInfo, - }) - - if (packagesImportsIncluded && "imports" in packageJsonObject) { - const importsForPackageImports = visitPackageImports({ - logger, - packageFileUrl, - packageName, - packageJsonObject, - packageInfo, - }) - - const { packageIsRoot, packageDirectoryRelativeUrl } = packageInfo - Object.keys(importsForPackageImports).forEach((from) => { - const to = importsForPackageImports[from] - - if (packageIsRoot) { - addTopLevelImportMapping({ from, to }) - } else { - const toScoped = - to[0] === "/" - ? to - : `./${packageDirectoryRelativeUrl}${to.startsWith("./") ? to.slice(2) : to}` - - addScopedImportMapping({ - scope: `./${packageDirectoryRelativeUrl}`, - from, - to: toScoped, - }) - - // when a package says './' maps to './' - // we must add something to say if we are already inside the package - // no need to ensure leading slash are scoped to the package - if (from === "./" && to === "./") { - addScopedImportMapping({ - scope: `./${packageDirectoryRelativeUrl}`, - from: `./${packageDirectoryRelativeUrl}`, - to: `./${packageDirectoryRelativeUrl}`, - }) - } else if (from === "/" && to === "/") { - addScopedImportMapping({ - scope: `./${packageDirectoryRelativeUrl}`, - from: `./${packageDirectoryRelativeUrl}`, - to: `./${packageDirectoryRelativeUrl}`, - }) - } - } - }) - } - - if (packagesSelfReference) { - const { packageIsRoot, packageDirectoryRelativeUrl } = packageInfo - - // allow import 'package-name/dir/file.js' in package-name files - if (packageIsRoot) { - addTopLevelImportMapping({ - from: `${packageName}/`, - to: `./${packageDirectoryRelativeUrl}`, - }) - } - // scoped allow import 'package-name/dir/file.js' in package-name files - else { - addScopedImportMapping({ - scope: `./${packageDirectoryRelativeUrl}`, - from: `${packageName}/`, - to: `./${packageDirectoryRelativeUrl}`, - }) - } - } - - if (packagesExportsIncluded && "exports" in packageJsonObject) { - const importsForPackageExports = visitPackageExports({ - logger, - packageFileUrl, - packageName, - packageJsonObject, - packageInfo, - packagesExportsPreference, - }) - - const { - importerIsRoot, - importerRelativeUrl, - packageIsRoot, - packageDirectoryRelativeUrl, - // packageDirectoryUrl, - // packageDirectoryUrlExpected, - } = packageInfo - - if (packageIsRoot && packagesSelfReference) { - Object.keys(importsForPackageExports).forEach((from) => { - const to = importsForPackageExports[from] - addTopLevelImportMapping({ - from, - to, - }) - }) - } else if (packageIsRoot) { - // ignore exports - } else { - Object.keys(importsForPackageExports).forEach((from) => { - const to = importsForPackageExports[from] - - // own package exports available to himself - if (importerIsRoot) { - // importer is the package himself, keep exports scoped - // otherwise the dependency exports would override the package exports. - if (importerPackageJsonObject.name === packageName) { - addScopedImportMapping({ - scope: `./${packageDirectoryRelativeUrl}`, - from, - to, - }) - if (from === packageName || from in imports === false) { - addTopLevelImportMapping({ from, to }) - } - } else { - addTopLevelImportMapping({ from, to }) - } - } else { - addScopedImportMapping({ - scope: `./${packageDirectoryRelativeUrl}`, - from, - to, - }) - } - - // now make package exports available to the importer - // if importer is root no need because the top level remapping does it - if (importerIsRoot) { - return - } - - // now make it available to the importer - // here if the importer is himself we could do stuff - // we should even handle the case earlier to prevent top level remapping - addScopedImportMapping({ scope: `./${importerRelativeUrl}`, from, to }) - }) - } - } - } - - const visitPackageMain = async ({ - packageFileUrl, - packageName, - packageJsonObject, - packageInfo: { - importerIsRoot, - importerRelativeUrl, - packageIsRoot, - packageIsProject, - packageDirectoryUrl, - packageDirectoryUrlExpected, - }, - }) => { - const self = packageIsRoot || packageIsProject - if (self && !packagesSelfReference) return - - const mainFileUrl = await resolvePackageMain({ - packageFileUrl, - packageJsonObject, - logger, - }) - - // it's possible to have no main - // like { main: "" } in package.json - // or a main that does not lead to an actual file - if (mainFileUrl === null) return - - const mainFileRelativeUrl = urlToRelativeUrl(mainFileUrl, rootProjectDirectoryUrl) - const from = packageName - const to = `./${mainFileRelativeUrl}` - - if (importerIsRoot) { - addTopLevelImportMapping({ from, to }) - } else { - addScopedImportMapping({ scope: `./${importerRelativeUrl}`, from, to }) - } - if (packageDirectoryUrl !== packageDirectoryUrlExpected) { - addScopedImportMapping({ scope: `./${importerRelativeUrl}`, from, to }) - } - } - - const visitDependencies = async ({ - packageFileUrl, - packageJsonObject, - includeDevDependencies, - }) => { - const dependencyMap = packageDependenciesFromPackageObject(packageJsonObject, { - includeDevDependencies, - }) - - await Promise.all( - Object.keys(dependencyMap).map(async (dependencyName) => { - const dependencyInfo = dependencyMap[dependencyName] - await visitDependency({ - packageFileUrl, - packageJsonObject, - dependencyName, - dependencyInfo, - }) - }), - ) - } - - const visitDependency = async ({ - packageFileUrl, - packageJsonObject, - dependencyName, - dependencyInfo, - }) => { - const dependencyData = await findDependency({ - packageFileUrl, - dependencyName, - }) - if (!dependencyData) { - logger[dependencyInfo.isOptional ? "debug" : "warn"]( - formatCannotFindPackageLog({ - dependencyName, - dependencyInfo, - packageFileUrl, - }), - ) - - return - } - - const { - packageFileUrl: dependencyPackageFileUrl, - packageJsonObject: dependencyPackageJsonObject, - } = dependencyData - - if (packageIsSeen(dependencyPackageFileUrl, packageFileUrl)) { - return - } - markPackageAsSeen(dependencyPackageFileUrl, packageFileUrl) - await visit({ - packageFileUrl: dependencyPackageFileUrl, - packageName: dependencyName, - packageJsonObject: dependencyPackageJsonObject, - importerPackageFileUrl: packageFileUrl, - importerPackageJsonObject: packageJsonObject, - }) - } - - const computePackageInfo = ({ packageFileUrl, packageName, importerPackageFileUrl }) => { - const importerIsRoot = importerPackageFileUrl === rootProjectPackageFileUrl - - const importerIsProject = importerPackageFileUrl === projectPackageFileUrl - - const importerPackageDirectoryUrl = resolveUrl("./", importerPackageFileUrl) - - const importerRelativeUrl = importerIsRoot - ? `${urlToBasename(rootProjectDirectoryUrl.slice(0, -1))}/` - : urlToRelativeUrl(importerPackageDirectoryUrl, rootProjectDirectoryUrl) - - const packageIsRoot = packageFileUrl === rootProjectPackageFileUrl - - const packageIsProject = packageFileUrl === projectPackageFileUrl - - const packageDirectoryUrl = resolveUrl("./", packageFileUrl) - - let packageDirectoryUrlExpected - if (packageIsProject && !packageIsRoot) { - packageDirectoryUrlExpected = importerPackageDirectoryUrl - } else { - packageDirectoryUrlExpected = `${importerPackageDirectoryUrl}node_modules/${packageName}/` - } - - const packageDirectoryRelativeUrl = urlToRelativeUrl( - packageDirectoryUrl, - rootProjectDirectoryUrl, - ) - - return { - importerIsRoot, - importerIsProject, - importerRelativeUrl, - packageIsRoot, - packageIsProject, - packageDirectoryUrl, - packageDirectoryUrlExpected, - packageDirectoryRelativeUrl, - } - } - - const addTopLevelImportMapping = ({ from, to }) => { - // we could think it's useless to remap from with to - // however it can be used to ensure a weaker remapping - // does not win over this specific file or folder - if (from === to) { - /** - * however remapping '/' to '/' is truly useless - * moreover it would make wrapImportMap create something like - * { - * imports: { - * "/": "/.dist/best/" - * } - * } - * that would append the wrapped folder twice - * */ - if (from === "/") return - } - - imports[from] = to - } - - const addScopedImportMapping = ({ scope, from, to }) => { - scopes[scope] = { - ...(scopes[scope] || {}), - [from]: to, - } - } - - const dependenciesCache = {} - const findDependency = ({ packageFileUrl, dependencyName }) => { - if (packageFileUrl in dependenciesCache === false) { - dependenciesCache[packageFileUrl] = {} - } - if (dependencyName in dependenciesCache[packageFileUrl]) { - return dependenciesCache[packageFileUrl][dependencyName] - } - const dependencyPromise = findNodeModulePackage({ - projectDirectoryUrl: rootProjectDirectoryUrl, - packageFileUrl, - dependencyName, - }) - dependenciesCache[packageFileUrl][dependencyName] = dependencyPromise - return dependencyPromise - } - - const projectPackageJsonObject = await readFile(projectPackageFileUrl, { as: "json" }) - const importerPackageFileUrl = projectPackageFileUrl - markPackageAsSeen(projectPackageFileUrl, importerPackageFileUrl) - - const packageName = projectPackageJsonObject.name - if (typeof packageName !== "string") { - logger.warn( - formatUnexpectedPackageNameLog({ packageName, packageFileUrl: projectPackageFileUrl }), - ) - return {} - } - - await visit({ - packageFileUrl: projectPackageFileUrl, - packageName: projectPackageJsonObject.name, - packageJsonObject: projectPackageJsonObject, - importerPackageFileUrl, - importerPackageJsonObject: null, - includeDevDependencies: projectPackageDevDependenciesIncluded, - }) - - // remove useless duplicates (scoped key+value already defined on imports) - Object.keys(scopes).forEach((key) => { - const scopedImports = scopes[key] - Object.keys(scopedImports).forEach((scopedImportKey) => { - if ( - scopedImportKey in imports && - imports[scopedImportKey] === scopedImports[scopedImportKey] - ) { - delete scopedImports[scopedImportKey] - } - }) - if (Object.keys(scopedImports).length === 0) { - delete scopes[key] - } - }) - // The importmap generated at this point is relative to the project directory url // In other words if you want to use that importmap you have to put it // inside projectDirectoryUrl (it cannot be nested in a subdirectory). - let importMap = { imports, scopes } - if (importMapFileRelativeUrl) { - // When there is an importMapFileRelativeUrl we will make remapping relative - // to the importmap file future location (where user will write it). - // This allows to put the importmap anywhere inside the projectDirectoryUrl. - // (If possible prefer to have it top level to avoid too many ../ - const importMapProjectUrl = resolveUrl("project.importmap", projectDirectoryUrl) - const importMapRealUrl = resolveUrl(importMapFileRelativeUrl, projectDirectoryUrl) - importMap = moveImportMap(importMap, importMapProjectUrl, importMapRealUrl) - } - importMap = sortImportMap(importMap) + const importMapForPackages = moveAndSort( + await getImportMapFromPackages({ + logLevel, + projectDirectoryUrl, + packagesExportsPreference: ["import", ...(targetExportsPreferences[target] || [])], + projectPackageDevDependenciesIncluded: dev, + ...rest, + }), + importMapFileRelativeUrl, + ) - return importMap + return importMapForPackages } -const packageDependenciesFromPackageObject = (packageObject, { includeDevDependencies }) => { - const packageDependencies = {} - - const { dependencies = {} } = packageObject - // https://npm.github.io/using-pkgs-docs/package-json/types/optionaldependencies.html - const { optionalDependencies = {} } = packageObject - Object.keys(dependencies).forEach((dependencyName) => { - packageDependencies[dependencyName] = { - type: "dependency", - isOptional: dependencyName in optionalDependencies, - versionPattern: dependencies[dependencyName], - } - }) - - const { peerDependencies = {} } = packageObject - const { peerDependenciesMeta = {} } = packageObject - Object.keys(peerDependencies).forEach((dependencyName) => { - packageDependencies[dependencyName] = { - type: "peerDependency", - versionPattern: peerDependencies[dependencyName], - isOptional: - dependencyName in peerDependenciesMeta && peerDependenciesMeta[dependencyName].optional, - } - }) - - if (includeDevDependencies) { - const { devDependencies = {} } = packageObject - Object.keys(devDependencies).forEach((dependencyName) => { - if (!packageDependencies.hasOwnProperty(dependencyName)) { - packageDependencies[dependencyName] = { - type: "devDependency", - versionPattern: devDependencies[dependencyName], - } - } - }) - } - - return packageDependencies +const targetExportsPreferences = { + browser: ["browser"], + node: ["node", "require"], } -const formatUnexpectedPackageNameLog = ({ packageName, packageFileUrl }) => { - return ` -package name field must be a string ---- package name field --- -${packageName} ---- package.json file path --- -${packageFileUrl} -` -} +const moveAndSort = (importmap, importMapFileRelativeUrl) => { + if (!importMapFileRelativeUrl) { + return sortImportMap(importmap) + } -const formatCannotFindPackageLog = ({ dependencyName, dependencyInfo, packageFileUrl }) => { - const dependencyIsOptional = dependencyInfo.isOptional - const dependencyType = dependencyInfo.type - const dependencyVersionPattern = dependencyInfo.versionPattern - const detailedMessage = createDetailedMessage( - dependencyIsOptional - ? `cannot find an optional ${dependencyType}.` - : `cannot find a ${dependencyType}.`, - { - [dependencyType]: `${dependencyName}@${dependencyVersionPattern}`, - "required by": urlToFileSystemPath(packageFileUrl), - }, - ) - return ` -${detailedMessage} -` + // When there is an importMapFileRelativeUrl we will make remapping relative + // to the importmap file future location (where user will write it). + // This allows to put the importmap anywhere inside the projectDirectoryUrl. + // (If possible prefer to have it top level to avoid too many ../) + const importMapProjectUrl = resolveUrl("project.importmap", "file://") + const importMapRealUrl = resolveUrl(importMapFileRelativeUrl, "file://") + const importmapMoved = moveImportMap(importmap, importMapProjectUrl, importMapRealUrl) + return sortImportMap(importmapMoved) } diff --git a/src/internal/codebase/parseSpecifiersFromFile.js b/src/internal/codebase/parseSpecifiersFromFile.js new file mode 100644 index 00000000..376acb4c --- /dev/null +++ b/src/internal/codebase/parseSpecifiersFromFile.js @@ -0,0 +1,99 @@ +import parser from "@babel/parser" +import traverse from "@babel/traverse" + +export const parseSpecifiersFromString = async ( + string, + { + sourceType = "module", + allowImportExportEverywhere = true, + allowAwaitOutsideFunction = true, + ranges = true, + jsx = true, + typescript = true, + flow = false, + ...options + } = {}, +) => { + const ast = parser.parse(string, { + sourceType, + allowImportExportEverywhere, + allowAwaitOutsideFunction, + ranges, + plugins: [ + // "estree", + "topLevelAwait", + "exportDefaultFrom", + ...(jsx ? ["jsx"] : []), + ...(typescript ? ["typescript"] : []), + ...(flow ? ["jsx"] : []), + ], + ...options, + }) + + const specifiers = {} + + const addSpecifier = ({ path, type }) => { + const specifier = path.node.value + specifiers[specifier] = { + // TODO: pass path.node.range as well, or dieally something like + // line + column + type, + } + } + + traverse.default(ast, { + // ImportExpression: (path) => { + // if (path.node.arguments[0].type !== "StringLiteral") { + // // Non-string argument, probably a variable or expression, e.g. + // // import(moduleId) + // // import('./' + moduleName) + // return + // } + // addSpecifier(path.get("arguments")[0]) + // }, + CallExpression: (path) => { + if (path.node.callee.type !== "Import") { + // Some other function call, not import(); + return + } + if (path.node.arguments[0].type !== "StringLiteral") { + // Non-string argument, probably a variable or expression, e.g. + // import(moduleId) + // import('./' + moduleName) + return + } + addSpecifier({ + path: path.get("arguments")[0], + type: "import-dynamic", + }) + }, + ExportAllDeclaration: (path) => { + addSpecifier({ + path: path.get("source"), + type: "export-all", + }) + }, + ExportNamedDeclaration: (path) => { + if (!path.node.source) { + // This export has no "source", so it's probably + // a local variable or function, e.g. + // export { varName } + // export const constName = ... + // export function funcName() {} + return + } + addSpecifier({ + path: path.get("source"), + type: "export-named", + }) + }, + ImportDeclaration: (path) => { + addSpecifier({ + path: path.get("source"), + type: "import-static", + }) + }, + }) + + return specifiers +} diff --git a/src/internal/applyPackageManualOverride.js b/src/internal/package/applyPackageManualOverride.js similarity index 100% rename from src/internal/applyPackageManualOverride.js rename to src/internal/package/applyPackageManualOverride.js diff --git a/src/internal/package/getImportMapFromPackages.js b/src/internal/package/getImportMapFromPackages.js new file mode 100644 index 00000000..d91d0eac --- /dev/null +++ b/src/internal/package/getImportMapFromPackages.js @@ -0,0 +1,541 @@ +import { createLogger, createDetailedMessage } from "@jsenv/logger" +import { + resolveUrl, + urlToRelativeUrl, + assertAndNormalizeDirectoryUrl, + urlToFileSystemPath, + urlToBasename, + readFile, +} from "@jsenv/util" +import { resolvePackageMain } from "./resolvePackageMain.js" +import { visitPackageImports } from "./visitPackageImports.js" +import { visitPackageExports } from "./visitPackageExports.js" +import { createFindNodeModulePackage } from "./node-module-resolution.js" + +export const getImportMapFromPackages = async ({ + // nothing is actually listening for this cancellationToken for now + // it's not very important but it would be better to register on it + // an stops what we are doing if asked to do so + // cancellationToken = createCancellationTokenForProcess(), + logLevel, + projectDirectoryUrl, + rootProjectDirectoryUrl, + + projectPackageDevDependenciesIncluded = process.env.NODE_ENV !== "production", + packagesExportsPreference = ["import", "browser"], + packagesExportsIncluded = true, + packagesSelfReference = true, + packagesImportsIncluded = true, + packagesManualOverrides = {}, + packageIncludedPredicate = () => true, +}) => { + const logger = createLogger({ logLevel }) + + projectDirectoryUrl = assertAndNormalizeDirectoryUrl(projectDirectoryUrl) + if (typeof rootProjectDirectoryUrl === "undefined") { + rootProjectDirectoryUrl = projectDirectoryUrl + } else { + rootProjectDirectoryUrl = assertAndNormalizeDirectoryUrl(rootProjectDirectoryUrl) + } + + const projectPackageFileUrl = resolveUrl("./package.json", projectDirectoryUrl) + const rootProjectPackageFileUrl = resolveUrl("./package.json", rootProjectDirectoryUrl) + const findNodeModulePackage = createFindNodeModulePackage(packagesManualOverrides) + + const imports = {} + const scopes = {} + const seen = {} + + const markPackageAsSeen = (packageFileUrl, importerPackageFileUrl) => { + if (packageFileUrl in seen) { + seen[packageFileUrl].push(importerPackageFileUrl) + } else { + seen[packageFileUrl] = [importerPackageFileUrl] + } + } + + const packageIsSeen = (packageFileUrl, importerPackageFileUrl) => { + return packageFileUrl in seen && seen[packageFileUrl].includes(importerPackageFileUrl) + } + + const visit = async ({ + packageFileUrl, + packageName, + packageJsonObject, + importerPackageFileUrl, + importerPackageJsonObject, + includeDevDependencies, + }) => { + if (!packageIncludedPredicate({ packageName, packageFileUrl, packageJsonObject })) { + return + } + + await visitDependencies({ + packageFileUrl, + packageJsonObject, + includeDevDependencies, + }) + await visitPackage({ + packageFileUrl, + packageName, + packageJsonObject, + importerPackageFileUrl, + importerPackageJsonObject, + }) + } + + const visitPackage = async ({ + packageFileUrl, + packageName, + packageJsonObject, + importerPackageFileUrl, + importerPackageJsonObject, + }) => { + const packageInfo = computePackageInfo({ + packageFileUrl, + packageName, + importerPackageFileUrl, + }) + + await visitPackageMain({ + packageFileUrl, + packageName, + packageJsonObject, + packageInfo, + }) + + if (packagesImportsIncluded && "imports" in packageJsonObject) { + const importsForPackageImports = visitPackageImports({ + logger, + packageFileUrl, + packageName, + packageJsonObject, + packageInfo, + }) + + const { packageIsRoot, packageDirectoryRelativeUrl } = packageInfo + Object.keys(importsForPackageImports).forEach((from) => { + const to = importsForPackageImports[from] + + if (packageIsRoot) { + addTopLevelImportMapping({ from, to }) + } else { + const toScoped = + to[0] === "/" + ? to + : `./${packageDirectoryRelativeUrl}${to.startsWith("./") ? to.slice(2) : to}` + + addScopedImportMapping({ + scope: `./${packageDirectoryRelativeUrl}`, + from, + to: toScoped, + }) + + // when a package says './' maps to './' + // we must add something to say if we are already inside the package + // no need to ensure leading slash are scoped to the package + if (from === "./" && to === "./") { + addScopedImportMapping({ + scope: `./${packageDirectoryRelativeUrl}`, + from: `./${packageDirectoryRelativeUrl}`, + to: `./${packageDirectoryRelativeUrl}`, + }) + } else if (from === "/" && to === "/") { + addScopedImportMapping({ + scope: `./${packageDirectoryRelativeUrl}`, + from: `./${packageDirectoryRelativeUrl}`, + to: `./${packageDirectoryRelativeUrl}`, + }) + } + } + }) + } + + if (packagesSelfReference) { + const { packageIsRoot, packageDirectoryRelativeUrl } = packageInfo + + // allow import 'package-name/dir/file.js' in package-name files + if (packageIsRoot) { + addTopLevelImportMapping({ + from: `${packageName}/`, + to: `./${packageDirectoryRelativeUrl}`, + }) + } + // scoped allow import 'package-name/dir/file.js' in package-name files + else { + addScopedImportMapping({ + scope: `./${packageDirectoryRelativeUrl}`, + from: `${packageName}/`, + to: `./${packageDirectoryRelativeUrl}`, + }) + } + } + + if (packagesExportsIncluded && "exports" in packageJsonObject) { + const importsForPackageExports = visitPackageExports({ + logger, + packageFileUrl, + packageName, + packageJsonObject, + packageInfo, + packagesExportsPreference, + }) + + const { + importerIsRoot, + importerRelativeUrl, + packageIsRoot, + packageDirectoryRelativeUrl, + // packageDirectoryUrl, + // packageDirectoryUrlExpected, + } = packageInfo + + if (packageIsRoot && packagesSelfReference) { + Object.keys(importsForPackageExports).forEach((from) => { + const to = importsForPackageExports[from] + addTopLevelImportMapping({ + from, + to, + }) + }) + } else if (packageIsRoot) { + // ignore exports + } else { + Object.keys(importsForPackageExports).forEach((from) => { + const to = importsForPackageExports[from] + + // own package exports available to himself + if (importerIsRoot) { + // importer is the package himself, keep exports scoped + // otherwise the dependency exports would override the package exports. + if (importerPackageJsonObject.name === packageName) { + addScopedImportMapping({ + scope: `./${packageDirectoryRelativeUrl}`, + from, + to, + }) + if (from === packageName || from in imports === false) { + addTopLevelImportMapping({ from, to }) + } + } else { + addTopLevelImportMapping({ from, to }) + } + } else { + addScopedImportMapping({ + scope: `./${packageDirectoryRelativeUrl}`, + from, + to, + }) + } + + // now make package exports available to the importer + // if importer is root no need because the top level remapping does it + if (importerIsRoot) { + return + } + + // now make it available to the importer + // here if the importer is himself we could do stuff + // we should even handle the case earlier to prevent top level remapping + addScopedImportMapping({ scope: `./${importerRelativeUrl}`, from, to }) + }) + } + } + } + + const visitPackageMain = async ({ + packageFileUrl, + packageName, + packageJsonObject, + packageInfo: { + importerIsRoot, + importerRelativeUrl, + packageIsRoot, + packageIsProject, + packageDirectoryUrl, + packageDirectoryUrlExpected, + }, + }) => { + const self = packageIsRoot || packageIsProject + if (self && !packagesSelfReference) return + + const mainFileUrl = await resolvePackageMain({ + packageFileUrl, + packageJsonObject, + logger, + }) + + // it's possible to have no main + // like { main: "" } in package.json + // or a main that does not lead to an actual file + if (mainFileUrl === null) return + + const mainFileRelativeUrl = urlToRelativeUrl(mainFileUrl, rootProjectDirectoryUrl) + const from = packageName + const to = `./${mainFileRelativeUrl}` + + if (importerIsRoot) { + addTopLevelImportMapping({ from, to }) + } else { + addScopedImportMapping({ scope: `./${importerRelativeUrl}`, from, to }) + } + if (packageDirectoryUrl !== packageDirectoryUrlExpected) { + addScopedImportMapping({ scope: `./${importerRelativeUrl}`, from, to }) + } + } + + const visitDependencies = async ({ + packageFileUrl, + packageJsonObject, + includeDevDependencies, + }) => { + const dependencyMap = packageDependenciesFromPackageObject(packageJsonObject, { + includeDevDependencies, + }) + + await Promise.all( + Object.keys(dependencyMap).map(async (dependencyName) => { + const dependencyInfo = dependencyMap[dependencyName] + await visitDependency({ + packageFileUrl, + packageJsonObject, + dependencyName, + dependencyInfo, + }) + }), + ) + } + + const visitDependency = async ({ + packageFileUrl, + packageJsonObject, + dependencyName, + dependencyInfo, + }) => { + const dependencyData = await findDependency({ + packageFileUrl, + dependencyName, + }) + if (!dependencyData) { + logger[dependencyInfo.isOptional ? "debug" : "warn"]( + formatCannotFindPackageLog({ + dependencyName, + dependencyInfo, + packageFileUrl, + }), + ) + + return + } + + const { + packageFileUrl: dependencyPackageFileUrl, + packageJsonObject: dependencyPackageJsonObject, + } = dependencyData + + if (packageIsSeen(dependencyPackageFileUrl, packageFileUrl)) { + return + } + markPackageAsSeen(dependencyPackageFileUrl, packageFileUrl) + await visit({ + packageFileUrl: dependencyPackageFileUrl, + packageName: dependencyName, + packageJsonObject: dependencyPackageJsonObject, + importerPackageFileUrl: packageFileUrl, + importerPackageJsonObject: packageJsonObject, + }) + } + + const computePackageInfo = ({ packageFileUrl, packageName, importerPackageFileUrl }) => { + const importerIsRoot = importerPackageFileUrl === rootProjectPackageFileUrl + + const importerIsProject = importerPackageFileUrl === projectPackageFileUrl + + const importerPackageDirectoryUrl = resolveUrl("./", importerPackageFileUrl) + + const importerRelativeUrl = importerIsRoot + ? `${urlToBasename(rootProjectDirectoryUrl.slice(0, -1))}/` + : urlToRelativeUrl(importerPackageDirectoryUrl, rootProjectDirectoryUrl) + + const packageIsRoot = packageFileUrl === rootProjectPackageFileUrl + + const packageIsProject = packageFileUrl === projectPackageFileUrl + + const packageDirectoryUrl = resolveUrl("./", packageFileUrl) + + let packageDirectoryUrlExpected + if (packageIsProject && !packageIsRoot) { + packageDirectoryUrlExpected = importerPackageDirectoryUrl + } else { + packageDirectoryUrlExpected = `${importerPackageDirectoryUrl}node_modules/${packageName}/` + } + + const packageDirectoryRelativeUrl = urlToRelativeUrl( + packageDirectoryUrl, + rootProjectDirectoryUrl, + ) + + return { + importerIsRoot, + importerIsProject, + importerRelativeUrl, + packageIsRoot, + packageIsProject, + packageDirectoryUrl, + packageDirectoryUrlExpected, + packageDirectoryRelativeUrl, + } + } + + const addTopLevelImportMapping = ({ from, to }) => { + // we could think it's useless to remap from with to + // however it can be used to ensure a weaker remapping + // does not win over this specific file or folder + if (from === to) { + /** + * however remapping '/' to '/' is truly useless + * moreover it would make wrapImportMap create something like + * { + * imports: { + * "/": "/.dist/best/" + * } + * } + * that would append the wrapped folder twice + * */ + if (from === "/") return + } + + imports[from] = to + } + + const addScopedImportMapping = ({ scope, from, to }) => { + scopes[scope] = { + ...(scopes[scope] || {}), + [from]: to, + } + } + + const dependenciesCache = {} + const findDependency = ({ packageFileUrl, dependencyName }) => { + if (packageFileUrl in dependenciesCache === false) { + dependenciesCache[packageFileUrl] = {} + } + if (dependencyName in dependenciesCache[packageFileUrl]) { + return dependenciesCache[packageFileUrl][dependencyName] + } + const dependencyPromise = findNodeModulePackage({ + projectDirectoryUrl: rootProjectDirectoryUrl, + packageFileUrl, + dependencyName, + }) + dependenciesCache[packageFileUrl][dependencyName] = dependencyPromise + return dependencyPromise + } + + const projectPackageJsonObject = await readFile(projectPackageFileUrl, { as: "json" }) + const importerPackageFileUrl = projectPackageFileUrl + markPackageAsSeen(projectPackageFileUrl, importerPackageFileUrl) + + const packageName = projectPackageJsonObject.name + if (typeof packageName !== "string") { + logger.warn( + formatUnexpectedPackageNameLog({ packageName, packageFileUrl: projectPackageFileUrl }), + ) + return {} + } + + await visit({ + packageFileUrl: projectPackageFileUrl, + packageName: projectPackageJsonObject.name, + packageJsonObject: projectPackageJsonObject, + importerPackageFileUrl, + importerPackageJsonObject: null, + includeDevDependencies: projectPackageDevDependenciesIncluded, + }) + + // remove useless duplicates (scoped key+value already defined on imports) + Object.keys(scopes).forEach((key) => { + const scopedImports = scopes[key] + Object.keys(scopedImports).forEach((scopedImportKey) => { + if ( + scopedImportKey in imports && + imports[scopedImportKey] === scopedImports[scopedImportKey] + ) { + delete scopedImports[scopedImportKey] + } + }) + if (Object.keys(scopedImports).length === 0) { + delete scopes[key] + } + }) + + return { imports, scopes } +} + +const packageDependenciesFromPackageObject = (packageObject, { includeDevDependencies }) => { + const packageDependencies = {} + + const { dependencies = {} } = packageObject + // https://npm.github.io/using-pkgs-docs/package-json/types/optionaldependencies.html + const { optionalDependencies = {} } = packageObject + Object.keys(dependencies).forEach((dependencyName) => { + packageDependencies[dependencyName] = { + type: "dependency", + isOptional: dependencyName in optionalDependencies, + versionPattern: dependencies[dependencyName], + } + }) + + const { peerDependencies = {} } = packageObject + const { peerDependenciesMeta = {} } = packageObject + Object.keys(peerDependencies).forEach((dependencyName) => { + packageDependencies[dependencyName] = { + type: "peerDependency", + versionPattern: peerDependencies[dependencyName], + isOptional: + dependencyName in peerDependenciesMeta && peerDependenciesMeta[dependencyName].optional, + } + }) + + if (includeDevDependencies) { + const { devDependencies = {} } = packageObject + Object.keys(devDependencies).forEach((dependencyName) => { + if (!packageDependencies.hasOwnProperty(dependencyName)) { + packageDependencies[dependencyName] = { + type: "devDependency", + versionPattern: devDependencies[dependencyName], + } + } + }) + } + + return packageDependencies +} + +const formatUnexpectedPackageNameLog = ({ packageName, packageFileUrl }) => { + return ` +package name field must be a string +--- package name field --- +${packageName} +--- package.json file path --- +${packageFileUrl} +` +} + +const formatCannotFindPackageLog = ({ dependencyName, dependencyInfo, packageFileUrl }) => { + const dependencyIsOptional = dependencyInfo.isOptional + const dependencyType = dependencyInfo.type + const dependencyVersionPattern = dependencyInfo.versionPattern + const detailedMessage = createDetailedMessage( + dependencyIsOptional + ? `cannot find an optional ${dependencyType}.` + : `cannot find a ${dependencyType}.`, + { + [dependencyType]: `${dependencyName}@${dependencyVersionPattern}`, + "required by": urlToFileSystemPath(packageFileUrl), + }, + ) + return ` +${detailedMessage} +` +} diff --git a/src/internal/node-module-resolution.js b/src/internal/package/node-module-resolution.js similarity index 96% rename from src/internal/node-module-resolution.js rename to src/internal/package/node-module-resolution.js index 5106518a..10649567 100644 --- a/src/internal/node-module-resolution.js +++ b/src/internal/package/node-module-resolution.js @@ -1,6 +1,6 @@ import { firstOperationMatching } from "@jsenv/cancellation" import { urlToRelativeUrl, resolveUrl } from "@jsenv/util" -import { memoizeAsyncFunctionByUrl } from "./memoizeAsyncFunctionByUrl.js" +import { memoizeAsyncFunctionByUrl } from "../memoizeAsyncFunctionByUrl.js" import { readPackageFile, PACKAGE_NOT_FOUND, PACKAGE_WITH_SYNTAX_ERROR } from "./readPackageFile.js" export const createFindNodeModulePackage = (packagesManualOverrides) => { diff --git a/src/internal/readPackageFile.js b/src/internal/package/readPackageFile.js similarity index 100% rename from src/internal/readPackageFile.js rename to src/internal/package/readPackageFile.js diff --git a/src/internal/resolveFile.js b/src/internal/package/resolveFile.js similarity index 100% rename from src/internal/resolveFile.js rename to src/internal/package/resolveFile.js diff --git a/src/internal/resolveNodeModule.js b/src/internal/package/resolveNodeModule.js similarity index 100% rename from src/internal/resolveNodeModule.js rename to src/internal/package/resolveNodeModule.js diff --git a/src/internal/resolvePackageMain.js b/src/internal/package/resolvePackageMain.js similarity index 100% rename from src/internal/resolvePackageMain.js rename to src/internal/package/resolvePackageMain.js diff --git a/src/internal/specifierIsRelative.js b/src/internal/package/specifierIsRelative.js similarity index 100% rename from src/internal/specifierIsRelative.js rename to src/internal/package/specifierIsRelative.js diff --git a/src/internal/visitPackageExports.js b/src/internal/package/visitPackageExports.js similarity index 100% rename from src/internal/visitPackageExports.js rename to src/internal/package/visitPackageExports.js diff --git a/src/internal/visitPackageImports.js b/src/internal/package/visitPackageImports.js similarity index 100% rename from src/internal/visitPackageImports.js rename to src/internal/package/visitPackageImports.js From 1a8d5bbb428c49ccb4e509897dfaac2c5c006f1c Mon Sep 17 00:00:00 2001 From: Damien Maillard Date: Sat, 6 Mar 2021 14:51:05 +0100 Subject: [PATCH 02/36] prepare for parsing codebase --- src/getImportMapFromNodeModules.js | 7 +- .../codebase/parseSpecifiersFromFile.js | 10 ++- test/parseSpecifiersFromFile.test.js | 65 +++++++++++++++++++ 3 files changed, 75 insertions(+), 7 deletions(-) create mode 100644 test/parseSpecifiersFromFile.test.js diff --git a/src/getImportMapFromNodeModules.js b/src/getImportMapFromNodeModules.js index a6fcbfdd..0d593c0d 100644 --- a/src/getImportMapFromNodeModules.js +++ b/src/getImportMapFromNodeModules.js @@ -10,9 +10,6 @@ export const getImportMapFromNodeModules = async ({ dev = false, ...rest }) => { - // The importmap generated at this point is relative to the project directory url - // In other words if you want to use that importmap you have to put it - // inside projectDirectoryUrl (it cannot be nested in a subdirectory). const importMapForPackages = moveAndSort( await getImportMapFromPackages({ logLevel, @@ -33,6 +30,7 @@ const targetExportsPreferences = { } const moveAndSort = (importmap, importMapFileRelativeUrl) => { + // At this point, importmap is relative to the project directory url if (!importMapFileRelativeUrl) { return sortImportMap(importmap) } @@ -40,7 +38,8 @@ const moveAndSort = (importmap, importMapFileRelativeUrl) => { // When there is an importMapFileRelativeUrl we will make remapping relative // to the importmap file future location (where user will write it). // This allows to put the importmap anywhere inside the projectDirectoryUrl. - // (If possible prefer to have it top level to avoid too many ../) + // If possible prefer top level because nesting importmap + // can lead to many relative path like ./file.js -> ../../file.js const importMapProjectUrl = resolveUrl("project.importmap", "file://") const importMapRealUrl = resolveUrl(importMapFileRelativeUrl, "file://") const importmapMoved = moveImportMap(importmap, importMapProjectUrl, importMapRealUrl) diff --git a/src/internal/codebase/parseSpecifiersFromFile.js b/src/internal/codebase/parseSpecifiersFromFile.js index 376acb4c..7964779c 100644 --- a/src/internal/codebase/parseSpecifiersFromFile.js +++ b/src/internal/codebase/parseSpecifiersFromFile.js @@ -1,8 +1,9 @@ import parser from "@babel/parser" import traverse from "@babel/traverse" +import { readFile, urlToFileSystemPath } from "@jsenv/util" -export const parseSpecifiersFromString = async ( - string, +export const parseSpecifiersFromFile = async ( + fileUrl, { sourceType = "module", allowImportExportEverywhere = true, @@ -14,8 +15,11 @@ export const parseSpecifiersFromString = async ( ...options } = {}, ) => { - const ast = parser.parse(string, { + const fileContent = await readFile(fileUrl, { as: "string" }) + + const ast = parser.parse(fileContent, { sourceType, + sourceFilename: urlToFileSystemPath(fileUrl), allowImportExportEverywhere, allowAwaitOutsideFunction, ranges, diff --git a/test/parseSpecifiersFromFile.test.js b/test/parseSpecifiersFromFile.test.js new file mode 100644 index 00000000..86acd2f9 --- /dev/null +++ b/test/parseSpecifiersFromFile.test.js @@ -0,0 +1,65 @@ +import { parseSpecifiersFromFile } from "../src/internal/codebase/parseSpecifiersFromFile.js" +import { writeFile, ensureEmptyDirectory, resolveUrl } from "@jsenv/util" +import { assert } from "@jsenv/assert" + +const testDirectoryUrl = resolveUrl("./fixtures/", import.meta.url) +const fileUrl = resolveUrl("test.js", testDirectoryUrl) + +// static top level import +{ + await writeFile( + fileUrl, + `import "./foo" +import "./bar.js" +`, + ) + const specifiers = await parseSpecifiersFromFile(fileUrl) + const actual = specifiers + const expected = { + "./foo": { type: "import-static" }, + "./bar.js": { type: "import-static" }, + } + assert({ actual, expected }) + await ensureEmptyDirectory(testDirectoryUrl) +} + +// dynamic top level import +{ + await writeFile( + fileUrl, + `import("./foo") +import(id) +`, + ) + const specifiers = await parseSpecifiersFromFile(fileUrl) + const actual = specifiers + const expected = { + "./foo": { type: "import-dynamic" }, + } + assert({ actual, expected }) + await ensureEmptyDirectory(testDirectoryUrl) +} + +// export from named +{ + await writeFile(fileUrl, `export {toto} from "./foo"`) + const specifiers = await parseSpecifiersFromFile(fileUrl) + const actual = specifiers + const expected = { + "./foo": { type: "export-named" }, + } + assert({ actual, expected }) + await ensureEmptyDirectory(testDirectoryUrl) +} + +// export from all +{ + await writeFile(fileUrl, `export * from "./foo"`) + const specifiers = await parseSpecifiersFromFile(fileUrl) + const actual = specifiers + const expected = { + "./foo": { type: "export-all" }, + } + assert({ actual, expected }) + await ensureEmptyDirectory(testDirectoryUrl) +} From a2482c82f82a03804689d94a66011cb242c640e9 Mon Sep 17 00:00:00 2001 From: Damien Maillard Date: Sat, 6 Mar 2021 15:38:30 +0100 Subject: [PATCH 03/36] wrap test dir --- .../{ => root}/node_modules/@jsenv/core/package.json | 0 .../self-import/self-import-6/{ => root}/package.json | 0 .../self-import/self-import-6/self-import-6.test.js | 2 +- 3 files changed, 1 insertion(+), 1 deletion(-) rename test/getImportMapFromNodeModules/self-import/self-import-6/{ => root}/node_modules/@jsenv/core/package.json (100%) rename test/getImportMapFromNodeModules/self-import/self-import-6/{ => root}/package.json (100%) diff --git a/test/getImportMapFromNodeModules/self-import/self-import-6/node_modules/@jsenv/core/package.json b/test/getImportMapFromNodeModules/self-import/self-import-6/root/node_modules/@jsenv/core/package.json similarity index 100% rename from test/getImportMapFromNodeModules/self-import/self-import-6/node_modules/@jsenv/core/package.json rename to test/getImportMapFromNodeModules/self-import/self-import-6/root/node_modules/@jsenv/core/package.json diff --git a/test/getImportMapFromNodeModules/self-import/self-import-6/package.json b/test/getImportMapFromNodeModules/self-import/self-import-6/root/package.json similarity index 100% rename from test/getImportMapFromNodeModules/self-import/self-import-6/package.json rename to test/getImportMapFromNodeModules/self-import/self-import-6/root/package.json diff --git a/test/getImportMapFromNodeModules/self-import/self-import-6/self-import-6.test.js b/test/getImportMapFromNodeModules/self-import/self-import-6/self-import-6.test.js index f5d9725a..1d0e7649 100644 --- a/test/getImportMapFromNodeModules/self-import/self-import-6/self-import-6.test.js +++ b/test/getImportMapFromNodeModules/self-import/self-import-6/self-import-6.test.js @@ -2,7 +2,7 @@ import { assert } from "@jsenv/assert" import { resolveUrl } from "@jsenv/util" import { getImportMapFromNodeModules } from "@jsenv/node-module-import-map" -const testDirectoryUrl = resolveUrl("./", import.meta.url) +const testDirectoryUrl = resolveUrl("./root/", import.meta.url) const actual = await getImportMapFromNodeModules({ projectDirectoryUrl: testDirectoryUrl, From d54143206f478e6989732fcd2090ba6c520cbe27 Mon Sep 17 00:00:00 2001 From: Damien Maillard Date: Sat, 6 Mar 2021 15:54:39 +0100 Subject: [PATCH 04/36] fix unit test --- .../self-import/self-import-6/self-import-6.test.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/test/getImportMapFromNodeModules/self-import/self-import-6/self-import-6.test.js b/test/getImportMapFromNodeModules/self-import/self-import-6/self-import-6.test.js index 1d0e7649..e1f7a7e6 100644 --- a/test/getImportMapFromNodeModules/self-import/self-import-6/self-import-6.test.js +++ b/test/getImportMapFromNodeModules/self-import/self-import-6/self-import-6.test.js @@ -6,6 +6,7 @@ const testDirectoryUrl = resolveUrl("./root/", import.meta.url) const actual = await getImportMapFromNodeModules({ projectDirectoryUrl: testDirectoryUrl, + dev: true, }) const expected = { imports: { @@ -21,7 +22,7 @@ const expected = { "@jsenv/core/": "./node_modules/@jsenv/core/", "@jsenv/core": "./node_modules/@jsenv/core/maindep.js", }, - "./self-import-6/": { + "./root/": { "@jsenv/core": "./index", }, }, From 7979089624c1963feeb3ec3a8eefd324d4c7dfe3 Mon Sep 17 00:00:00 2001 From: Damien Maillard Date: Sat, 6 Mar 2021 15:55:02 +0100 Subject: [PATCH 05/36] split visit package exports in 2 --- .../package/getImportMapFromPackages.js | 54 +++++- src/internal/package/visitPackageExports.js | 172 +++++++++--------- 2 files changed, 132 insertions(+), 94 deletions(-) diff --git a/src/internal/package/getImportMapFromPackages.js b/src/internal/package/getImportMapFromPackages.js index d91d0eac..c945383d 100644 --- a/src/internal/package/getImportMapFromPackages.js +++ b/src/internal/package/getImportMapFromPackages.js @@ -172,13 +172,47 @@ export const getImportMapFromPackages = async ({ } if (packagesExportsIncluded && "exports" in packageJsonObject) { - const importsForPackageExports = visitPackageExports({ - logger, + const importsForPackageExports = {} + visitPackageExports({ packageFileUrl, - packageName, packageJsonObject, - packageInfo, + packageName, + projectDirectoryUrl, packagesExportsPreference, + onExport: ({ key, value }) => { + const from = key + const to = value + + if (from.indexOf("*") === -1) { + importsForPackageExports[from] = to + return + } + + if ( + from.endsWith("/*") && + to.endsWith("/*") && + // ensure ends with '*' AND there is only one '*' occurence + to.indexOf("*") === to.length - 1 + ) { + const fromWithouTrailingStar = from.slice(0, -1) + const toWithoutTrailingStar = to.slice(0, -1) + importsForPackageExports[fromWithouTrailingStar] = toWithoutTrailingStar + return + } + + logger.warn( + formatWilcardExportsIgnoredWarning({ + key, + value, + packageFileUrl, + }), + ) + }, + onWarn: (warning) => { + logger.warn(` + ${warning} + `) + }, }) const { @@ -512,6 +546,18 @@ const packageDependenciesFromPackageObject = (packageObject, { includeDevDepende return packageDependencies } +const formatWilcardExportsIgnoredWarning = ({ key, value, packageFileUrl }) => { + return `Ignoring export using "*" because it is not supported by importmap. +--- key --- +${key} +--- value --- +${value} +--- package.json path --- +${urlToFileSystemPath(packageFileUrl)} +--- see also --- +https://github.com/WICG/import-maps/issues/232` +} + const formatUnexpectedPackageNameLog = ({ packageName, packageFileUrl }) => { return ` package name field must be a string diff --git a/src/internal/package/visitPackageExports.js b/src/internal/package/visitPackageExports.js index 7f709ccc..a1a90ba9 100644 --- a/src/internal/package/visitPackageExports.js +++ b/src/internal/package/visitPackageExports.js @@ -1,73 +1,38 @@ // https://nodejs.org/dist/latest-v13.x/docs/api/esm.html#esm_package_exports -import { urlToFileSystemPath } from "@jsenv/util" +import { urlToFileSystemPath, urlToRelativeUrl, resolveUrl } from "@jsenv/util" import { specifierIsRelative } from "./specifierIsRelative.js" export const visitPackageExports = ({ - logger, packageFileUrl, - packageName, packageJsonObject, - packageInfo: { packageDirectoryRelativeUrl }, + packageExports = packageJsonObject.exports, + packageName = packageJsonObject.name, + projectDirectoryUrl, packagesExportsPreference, + onExport, + onWarn, }) => { - const importsForPackageExports = {} - - const packageFilePath = urlToFileSystemPath(packageFileUrl) - const { exports: packageExports } = packageJsonObject - - // false is allowed as laternative to exports: {} + // false is allowed as alternative to exports: {} if (packageExports === false) { - return importsForPackageExports + return } - const addRemapping = ({ from, to }) => { - if (from.indexOf("*") === -1) { - importsForPackageExports[from] = to - return - } - - if ( - from.endsWith("/*") && - to.endsWith("/*") && - // ensure ends with '*' AND there is only one '*' occurence - to.indexOf("*") === to.length - 1 - ) { - const fromWithouTrailingStar = from.slice(0, -1) - const toWithoutTrailingStar = to.slice(0, -1) - importsForPackageExports[fromWithouTrailingStar] = toWithoutTrailingStar - return - } - - logger.warn(`Ignoring export using "*" because it is not supported by importmap. ---- key --- -${from} ---- value --- -${to} ---- package.json path --- -${packageFilePath} ---- see also --- -https://github.com/WICG/import-maps/issues/232`) - } + const packageDirectoryUrl = resolveUrl("./", packageFileUrl) + const packageDirectoryRelativeUrl = urlToRelativeUrl(packageDirectoryUrl, projectDirectoryUrl) // exports used to indicate the main file if (typeof packageExports === "string") { - addRemapping({ - from: packageName, - to: addressToDestination(packageExports, packageDirectoryRelativeUrl), + onExport({ + key: packageName, + value: addressToDestination(packageExports, packageDirectoryRelativeUrl), }) - return importsForPackageExports + return } if (typeof packageExports !== "object" || packageExports === null) { - logger.warn(` -exports of package.json must be an object. ---- package.json exports --- -${packageExports} ---- package.json path --- -${packageFilePath} -`) - return importsForPackageExports + onWarn(formatUnexpectedExportsWarning({ packageExports, packageFileUrl })) + return } const packageExportsKeys = Object.keys(packageExports) @@ -76,28 +41,18 @@ ${packageFilePath} const someSpecifierDoesNotStartsWithDot = packageExportsKeys.some((key) => !key.startsWith(".")) if (someSpecifierDoesNotStartsWithDot) { // see https://nodejs.org/dist/latest-v13.x/docs/api/esm.html#esm_exports_sugar - logger.error(` -exports of package.json mixes conditional exports and direct exports. ---- package.json path --- -${packageFilePath} -`) - return importsForPackageExports + onWarn(formatMixedExportsWarning({ packageFileUrl })) + return } } - packageExportsKeys.forEach((specifier) => { - if (!specifierIsRelative(specifier)) { - logger.warn(` -found unexpected specifier in exports of package.json, it must be relative to package.json. ---- specifier --- -${specifier} ---- package.json path --- -${packageFilePath} -`) + packageExportsKeys.forEach((key) => { + if (!specifierIsRelative(key)) { + onWarn(formatAbsoluteKeyInExportsWarning({ key, packageFileUrl })) return } - const value = packageExports[specifier] + const value = packageExports[key] let address if (typeof value === "object") { @@ -115,38 +70,32 @@ ${packageFilePath} } else if (typeof value === "string") { address = value } else { - logger.warn(` -found unexpected address in exports of package.json, it must be a string. ---- address --- -${address} ---- specifier --- -${specifier} ---- package.json path --- -${packageFilePath} -`) + onWarn( + formatUnexpectedValueInExportsWarning({ + value, + key, + packageFileUrl, + }), + ) return } if (!specifierIsRelative(address)) { - logger.warn(` -found unexpected address in exports of package.json, it must be relative to package.json. ---- address --- -${address} ---- specifier --- -${specifier} ---- package.json path --- -${packageFilePath} -`) + onWarn( + formatAbsoluteValueInExportsWarning({ + value: address, + key, + packageFileUrl, + }), + ) return } - addRemapping({ - from: specifierToSource(specifier, packageName), - to: addressToDestination(address, packageDirectoryRelativeUrl), + onExport({ + key: specifierToSource(key, packageName), + value: addressToDestination(address, packageDirectoryRelativeUrl), }) }) - - return importsForPackageExports } const specifierToSource = (specifier, packageName) => { @@ -189,3 +138,46 @@ const readFavoredKey = (object, favoredKeys) => { return undefined } + +const formatUnexpectedExportsWarning = ({ packageExports, packageFileUrl }) => { + return `exports of package.json must be an object. +--- package.json exports --- +${packageExports} +--- package.json path --- +${urlToFileSystemPath(packageFileUrl)} +` +} + +const formatMixedExportsWarning = ({ packageFileUrl }) => { + return `exports of package.json mixes conditional exports and direct exports. +--- package.json path --- +${urlToFileSystemPath(packageFileUrl)}` +} + +const formatAbsoluteKeyInExportsWarning = ({ key, packageFileUrl }) => { + return `found unexpected key in exports of package.json, key must be relative to package.json. +--- key --- +${key} +--- package.json path --- +${urlToFileSystemPath(packageFileUrl)}` +} + +const formatUnexpectedValueInExportsWarning = ({ value, key, packageFileUrl }) => { + return `found unexpected value in exports of package.json, it must be a string. +--- value --- +${value} +--- key --- +${key} +--- package.json path --- +${urlToFileSystemPath(packageFileUrl)}` +} + +const formatAbsoluteValueInExportsWarning = ({ value, key, packageFileUrl }) => { + return `found unexpected value in exports of package.json, value must be relative to package.json. +--- value --- +${value} +--- key --- +${key} +--- package.json path --- +${urlToFileSystemPath(packageFileUrl)}` +} From f2b183dd57fb3cbfe81cf8475a89dec1131c0518 Mon Sep 17 00:00:00 2001 From: Damien Maillard Date: Sat, 6 Mar 2021 18:07:34 +0100 Subject: [PATCH 06/36] test and fix visitPackageExports on nested condition --- src/internal/package/visitPackageExports.js | 244 +++++++++++------- .../exports-and-main/exports-and-main.test.js | 2 +- .../{ => root}/node_modules/foo/file.cjs | 0 .../{ => root}/node_modules/foo/index.js | 0 .../{ => root}/node_modules/foo/package.json | 0 .../exports-and-main/{ => root}/package.json | 0 .../exports-condition-nested.test.js | 37 +++ .../root/node_modules/foo/package.json | 9 + .../root}/package.json | 0 .../exports-directory-scoped.test.js | 2 +- .../{ => root}/node_modules/foo/index.js | 0 .../node_modules/exporting-folder/index.js | 0 .../exporting-folder/package.json | 0 .../{ => root}/node_modules/foo/package.json | 2 +- .../root/package.json | 6 + 15 files changed, 207 insertions(+), 95 deletions(-) rename test/getImportMapFromNodeModules/package-exports-field/exports-and-main/{ => root}/node_modules/foo/file.cjs (100%) rename test/getImportMapFromNodeModules/package-exports-field/exports-and-main/{ => root}/node_modules/foo/index.js (100%) rename test/getImportMapFromNodeModules/package-exports-field/exports-and-main/{ => root}/node_modules/foo/package.json (100%) rename test/getImportMapFromNodeModules/package-exports-field/exports-and-main/{ => root}/package.json (100%) create mode 100644 test/getImportMapFromNodeModules/package-exports-field/exports-condition-nested/exports-condition-nested.test.js create mode 100644 test/getImportMapFromNodeModules/package-exports-field/exports-condition-nested/root/node_modules/foo/package.json rename test/getImportMapFromNodeModules/package-exports-field/{exports-directory-scoped => exports-condition-nested/root}/package.json (100%) rename test/getImportMapFromNodeModules/package-exports-field/exports-directory-scoped/{ => root}/node_modules/foo/index.js (100%) rename test/getImportMapFromNodeModules/package-exports-field/exports-directory-scoped/{ => root}/node_modules/foo/node_modules/exporting-folder/index.js (100%) rename test/getImportMapFromNodeModules/package-exports-field/exports-directory-scoped/{ => root}/node_modules/foo/node_modules/exporting-folder/package.json (100%) rename test/getImportMapFromNodeModules/package-exports-field/exports-directory-scoped/{ => root}/node_modules/foo/package.json (76%) create mode 100644 test/getImportMapFromNodeModules/package-exports-field/exports-directory-scoped/root/package.json diff --git a/src/internal/package/visitPackageExports.js b/src/internal/package/visitPackageExports.js index a1a90ba9..463c3af5 100644 --- a/src/internal/package/visitPackageExports.js +++ b/src/internal/package/visitPackageExports.js @@ -13,91 +13,149 @@ export const visitPackageExports = ({ onExport, onWarn, }) => { - // false is allowed as alternative to exports: {} - if (packageExports === false) { - return - } - const packageDirectoryUrl = resolveUrl("./", packageFileUrl) const packageDirectoryRelativeUrl = urlToRelativeUrl(packageDirectoryUrl, projectDirectoryUrl) - // exports used to indicate the main file - if (typeof packageExports === "string") { - onExport({ - key: packageName, - value: addressToDestination(packageExports, packageDirectoryRelativeUrl), - }) - return - } + visitExportsSubpath(packageExports, packagesExportsPreference, { + onUnexpectedPackageExports: ({ packageExportsValue, packageExportsValuePath }) => { + onWarn( + formatExportsIsUnexpectedWarning({ + packageExportsValue, + packageExportsValuePath, + packageFileUrl, + }), + ) + }, + onMixedPackageExports: ({ packageExportsValue, packageExportsValuePath }) => { + // see https://nodejs.org/dist/latest-v13.x/docs/api/esm.html#esm_exports_sugar + onWarn( + formatExportsUnexpectedMixWarning({ + packageExportsValue, + packageExportsValuePath, + packageFileUrl, + }), + ) + }, + onSubpathPackageExport: ({ key, value, valuePath }) => { + if (!specifierIsRelative(key)) { + onWarn( + formatExportsKeyMustBeRelativeWarning({ + key, + keyPath: valuePath.slice(0, -1), + packageFileUrl, + }), + ) + return + } + if (typeof value !== "string") { + onWarn( + formatExportsValueMustBeStringWarning({ + value, + valuePath, + packageFileUrl, + }), + ) + return + } + if (!specifierIsRelative(value)) { + onWarn( + formatExportsValueMustBeRelativeWarning({ + value, + valuePath, + packageFileUrl, + }), + ) + return + } - if (typeof packageExports !== "object" || packageExports === null) { - onWarn(formatUnexpectedExportsWarning({ packageExports, packageFileUrl })) - return - } + onExport({ + key: specifierToSource(key, packageName), + value: addressToDestination(value, packageDirectoryRelativeUrl), + }) + }, + }) +} - const packageExportsKeys = Object.keys(packageExports) - const someSpecifierStartsWithDot = packageExportsKeys.some((key) => key.startsWith(".")) - if (someSpecifierStartsWithDot) { - const someSpecifierDoesNotStartsWithDot = packageExportsKeys.some((key) => !key.startsWith(".")) - if (someSpecifierDoesNotStartsWithDot) { - // see https://nodejs.org/dist/latest-v13.x/docs/api/esm.html#esm_exports_sugar - onWarn(formatMixedExportsWarning({ packageFileUrl })) +const visitExportsSubpath = ( + packageExports, + packageExportsConditions, + { onUnexpectedPackageExports, onMixedPackageExports, onSubpathPackageExport }, +) => { + const visitValue = (packageExportsValue, { valuePath }) => { + // false is allowed as alternative to exports: {} + if (packageExportsValue === false) { return } - } - packageExportsKeys.forEach((key) => { - if (!specifierIsRelative(key)) { - onWarn(formatAbsoluteKeyInExportsWarning({ key, packageFileUrl })) + if (typeof packageExportsValue === "string") { + const firstNonConditionKey = valuePath + .slice() + .reverse() + .find((key) => key.startsWith(".")) + const key = firstNonConditionKey || "." + onSubpathPackageExport({ + value: packageExportsValue, + valuePath, + key, + }) return } - const value = packageExports[key] - let address - - if (typeof value === "object") { - address = readFavoredKey(value, packagesExportsPreference) + if (typeof packageExportsValue !== "object" && packageExportsValue !== null) { + onUnexpectedPackageExports({ + packageExportsValue, + packageExportsValuePath: valuePath, + }) + return + } - if (!address) { + const keys = Object.keys(packageExportsValue) + const everyKeyDoesNotStartsWithDot = keys.every((key) => !key.startsWith(".")) + if (everyKeyDoesNotStartsWithDot) { + const bestConditionKey = findBestConditionKey(keys, packageExportsConditions) + if (!bestConditionKey) { return } - if (typeof address === "object") { - address = readFavoredKey(address, packagesExportsPreference) - if (!address) { - return - } - } - } else if (typeof value === "string") { - address = value - } else { - onWarn( - formatUnexpectedValueInExportsWarning({ - value, - key, - packageFileUrl, - }), - ) + const bestExports = packageExportsValue[bestConditionKey] + visitValue(bestExports, { + valuePath: [...valuePath, bestConditionKey], + }) return } - if (!specifierIsRelative(address)) { - onWarn( - formatAbsoluteValueInExportsWarning({ - value: address, - key, - packageFileUrl, - }), - ) + const everyKeyStartsWithDot = keys.every((key) => key.startsWith(".")) + if (everyKeyStartsWithDot) { + keys.forEach((key) => { + visitValue(packageExportsValue[key], { + valuePath: [...valuePath, key], + }) + }) return } - onExport({ - key: specifierToSource(key, packageName), - value: addressToDestination(address, packageDirectoryRelativeUrl), + onMixedPackageExports({ + packageExportsValue, + packageExportsValuePath: valuePath, }) + } + visitValue(packageExports, { + valuePath: ["exports"], }) } +const findBestConditionKey = (availableKeys, exportsConditions) => { + const conditionKey = exportsConditions.find((key) => availableKeys.includes(key)) + if (conditionKey) { + return conditionKey + } + + if (availableKeys.includes("default")) { + return "default" + } + + return undefined +} + const specifierToSource = (specifier, packageName) => { if (specifier === ".") { return packageName @@ -126,58 +184,60 @@ const addressToDestination = (address, packageDirectoryRelativeUrl) => { return `./${packageDirectoryRelativeUrl}${address}` } -const readFavoredKey = (object, favoredKeys) => { - const favoredKey = favoredKeys.find((key) => object.hasOwnProperty(key)) - if (favoredKey) { - return object[favoredKey] - } - - if (object.hasOwnProperty("default")) { - return object.default - } - - return undefined -} - -const formatUnexpectedExportsWarning = ({ packageExports, packageFileUrl }) => { - return `exports of package.json must be an object. ---- package.json exports --- -${packageExports} +const formatExportsIsUnexpectedWarning = ({ + packageExportsValue, + packageExportsValuePath, + packageFileUrl, +}) => { + return `unexpected value in package.json exports field: value must be an object or a string. +--- value --- +${packageExportsValue} +--- value path --- +${packageExportsValuePath.join(".")} --- package.json path --- -${urlToFileSystemPath(packageFileUrl)} -` +${urlToFileSystemPath(packageFileUrl)}` } -const formatMixedExportsWarning = ({ packageFileUrl }) => { - return `exports of package.json mixes conditional exports and direct exports. +const formatExportsUnexpectedMixWarning = ({ + packageExportsValue, + packageExportsValuePath, + packageFileUrl, +}) => { + return `unexpected package.json exports field: cannot mix conditional and subpath exports. +--- value --- +${JSON.stringify(packageExportsValue, null, " ")} +--- value path --- +${packageExportsValuePath.join(".")} --- package.json path --- ${urlToFileSystemPath(packageFileUrl)}` } -const formatAbsoluteKeyInExportsWarning = ({ key, packageFileUrl }) => { - return `found unexpected key in exports of package.json, key must be relative to package.json. +const formatExportsKeyMustBeRelativeWarning = ({ key, keyPath, packageFileUrl }) => { + return `unexpected key in package.json exports field: key must be relative. --- key --- ${key} +--- key path --- +${keyPath.join(".")} --- package.json path --- ${urlToFileSystemPath(packageFileUrl)}` } -const formatUnexpectedValueInExportsWarning = ({ value, key, packageFileUrl }) => { - return `found unexpected value in exports of package.json, it must be a string. +const formatExportsValueMustBeStringWarning = ({ value, valuePath, packageFileUrl }) => { + return `unexpected value in package.json exports field: value must be a string. --- value --- ${value} ---- key --- -${key} +--- value path --- +${valuePath.join(".")} --- package.json path --- ${urlToFileSystemPath(packageFileUrl)}` } -const formatAbsoluteValueInExportsWarning = ({ value, key, packageFileUrl }) => { - return `found unexpected value in exports of package.json, value must be relative to package.json. +const formatExportsValueMustBeRelativeWarning = ({ value, valuePath, packageFileUrl }) => { + return `unexpected value in package.json exports field: value must be relative. --- value --- ${value} ---- key --- -${key} +--- value path --- +${valuePath.join(".")} --- package.json path --- ${urlToFileSystemPath(packageFileUrl)}` } diff --git a/test/getImportMapFromNodeModules/package-exports-field/exports-and-main/exports-and-main.test.js b/test/getImportMapFromNodeModules/package-exports-field/exports-and-main/exports-and-main.test.js index 76dc3a75..22f42bda 100644 --- a/test/getImportMapFromNodeModules/package-exports-field/exports-and-main/exports-and-main.test.js +++ b/test/getImportMapFromNodeModules/package-exports-field/exports-and-main/exports-and-main.test.js @@ -2,7 +2,7 @@ import { assert } from "@jsenv/assert" import { resolveUrl } from "@jsenv/util" import { getImportMapFromNodeModules } from "@jsenv/node-module-import-map" -const testDirectoryUrl = resolveUrl("./", import.meta.url) +const testDirectoryUrl = resolveUrl("./root/", import.meta.url) const actual = await getImportMapFromNodeModules({ projectDirectoryUrl: testDirectoryUrl, diff --git a/test/getImportMapFromNodeModules/package-exports-field/exports-and-main/node_modules/foo/file.cjs b/test/getImportMapFromNodeModules/package-exports-field/exports-and-main/root/node_modules/foo/file.cjs similarity index 100% rename from test/getImportMapFromNodeModules/package-exports-field/exports-and-main/node_modules/foo/file.cjs rename to test/getImportMapFromNodeModules/package-exports-field/exports-and-main/root/node_modules/foo/file.cjs diff --git a/test/getImportMapFromNodeModules/package-exports-field/exports-and-main/node_modules/foo/index.js b/test/getImportMapFromNodeModules/package-exports-field/exports-and-main/root/node_modules/foo/index.js similarity index 100% rename from test/getImportMapFromNodeModules/package-exports-field/exports-and-main/node_modules/foo/index.js rename to test/getImportMapFromNodeModules/package-exports-field/exports-and-main/root/node_modules/foo/index.js diff --git a/test/getImportMapFromNodeModules/package-exports-field/exports-and-main/node_modules/foo/package.json b/test/getImportMapFromNodeModules/package-exports-field/exports-and-main/root/node_modules/foo/package.json similarity index 100% rename from test/getImportMapFromNodeModules/package-exports-field/exports-and-main/node_modules/foo/package.json rename to test/getImportMapFromNodeModules/package-exports-field/exports-and-main/root/node_modules/foo/package.json diff --git a/test/getImportMapFromNodeModules/package-exports-field/exports-and-main/package.json b/test/getImportMapFromNodeModules/package-exports-field/exports-and-main/root/package.json similarity index 100% rename from test/getImportMapFromNodeModules/package-exports-field/exports-and-main/package.json rename to test/getImportMapFromNodeModules/package-exports-field/exports-and-main/root/package.json diff --git a/test/getImportMapFromNodeModules/package-exports-field/exports-condition-nested/exports-condition-nested.test.js b/test/getImportMapFromNodeModules/package-exports-field/exports-condition-nested/exports-condition-nested.test.js new file mode 100644 index 00000000..06e897ab --- /dev/null +++ b/test/getImportMapFromNodeModules/package-exports-field/exports-condition-nested/exports-condition-nested.test.js @@ -0,0 +1,37 @@ +import { assert } from "@jsenv/assert" +import { resolveUrl } from "@jsenv/util" +import { getImportMapFromNodeModules } from "@jsenv/node-module-import-map" + +const testDirectoryUrl = resolveUrl("./root/", import.meta.url) + +{ + const importMap = await getImportMapFromNodeModules({ + projectDirectoryUrl: testDirectoryUrl, + target: "node", + packagesSelfReference: false, + }) + const actual = importMap + const expected = { + imports: { + foo: "./node_modules/foo/feature-node.mjs", + }, + scopes: {}, + } + assert({ actual, expected }) +} + +{ + const importMap = await getImportMapFromNodeModules({ + projectDirectoryUrl: testDirectoryUrl, + target: "browser", + packagesSelfReference: false, + }) + const actual = importMap + const expected = { + imports: { + foo: "./node_modules/foo/feature.mjs", + }, + scopes: {}, + } + assert({ actual, expected }) +} diff --git a/test/getImportMapFromNodeModules/package-exports-field/exports-condition-nested/root/node_modules/foo/package.json b/test/getImportMapFromNodeModules/package-exports-field/exports-condition-nested/root/node_modules/foo/package.json new file mode 100644 index 00000000..11846a2f --- /dev/null +++ b/test/getImportMapFromNodeModules/package-exports-field/exports-condition-nested/root/node_modules/foo/package.json @@ -0,0 +1,9 @@ +{ + "exports": { + "node": { + "import": "./feature-node.mjs", + "require": "./feature-node.cjs" + }, + "default": "./feature.mjs" + } +} diff --git a/test/getImportMapFromNodeModules/package-exports-field/exports-directory-scoped/package.json b/test/getImportMapFromNodeModules/package-exports-field/exports-condition-nested/root/package.json similarity index 100% rename from test/getImportMapFromNodeModules/package-exports-field/exports-directory-scoped/package.json rename to test/getImportMapFromNodeModules/package-exports-field/exports-condition-nested/root/package.json diff --git a/test/getImportMapFromNodeModules/package-exports-field/exports-directory-scoped/exports-directory-scoped.test.js b/test/getImportMapFromNodeModules/package-exports-field/exports-directory-scoped/exports-directory-scoped.test.js index 3dea6c3f..9e38ae91 100644 --- a/test/getImportMapFromNodeModules/package-exports-field/exports-directory-scoped/exports-directory-scoped.test.js +++ b/test/getImportMapFromNodeModules/package-exports-field/exports-directory-scoped/exports-directory-scoped.test.js @@ -2,7 +2,7 @@ import { assert } from "@jsenv/assert" import { resolveUrl } from "@jsenv/util" import { getImportMapFromNodeModules } from "@jsenv/node-module-import-map" -const testDirectoryUrl = resolveUrl("./", import.meta.url) +const testDirectoryUrl = resolveUrl("./root/", import.meta.url) const actual = await getImportMapFromNodeModules({ projectDirectoryUrl: testDirectoryUrl, diff --git a/test/getImportMapFromNodeModules/package-exports-field/exports-directory-scoped/node_modules/foo/index.js b/test/getImportMapFromNodeModules/package-exports-field/exports-directory-scoped/root/node_modules/foo/index.js similarity index 100% rename from test/getImportMapFromNodeModules/package-exports-field/exports-directory-scoped/node_modules/foo/index.js rename to test/getImportMapFromNodeModules/package-exports-field/exports-directory-scoped/root/node_modules/foo/index.js diff --git a/test/getImportMapFromNodeModules/package-exports-field/exports-directory-scoped/node_modules/foo/node_modules/exporting-folder/index.js b/test/getImportMapFromNodeModules/package-exports-field/exports-directory-scoped/root/node_modules/foo/node_modules/exporting-folder/index.js similarity index 100% rename from test/getImportMapFromNodeModules/package-exports-field/exports-directory-scoped/node_modules/foo/node_modules/exporting-folder/index.js rename to test/getImportMapFromNodeModules/package-exports-field/exports-directory-scoped/root/node_modules/foo/node_modules/exporting-folder/index.js diff --git a/test/getImportMapFromNodeModules/package-exports-field/exports-directory-scoped/node_modules/foo/node_modules/exporting-folder/package.json b/test/getImportMapFromNodeModules/package-exports-field/exports-directory-scoped/root/node_modules/foo/node_modules/exporting-folder/package.json similarity index 100% rename from test/getImportMapFromNodeModules/package-exports-field/exports-directory-scoped/node_modules/foo/node_modules/exporting-folder/package.json rename to test/getImportMapFromNodeModules/package-exports-field/exports-directory-scoped/root/node_modules/foo/node_modules/exporting-folder/package.json diff --git a/test/getImportMapFromNodeModules/package-exports-field/exports-directory-scoped/node_modules/foo/package.json b/test/getImportMapFromNodeModules/package-exports-field/exports-directory-scoped/root/node_modules/foo/package.json similarity index 76% rename from test/getImportMapFromNodeModules/package-exports-field/exports-directory-scoped/node_modules/foo/package.json rename to test/getImportMapFromNodeModules/package-exports-field/exports-directory-scoped/root/node_modules/foo/package.json index 12b945ac..b472fea8 100644 --- a/test/getImportMapFromNodeModules/package-exports-field/exports-directory-scoped/node_modules/foo/package.json +++ b/test/getImportMapFromNodeModules/package-exports-field/exports-directory-scoped/root/node_modules/foo/package.json @@ -3,6 +3,6 @@ "exporting-folder": "*" }, "exports": { - "ding": "dong" + "./ding": "./dong" } } diff --git a/test/getImportMapFromNodeModules/package-exports-field/exports-directory-scoped/root/package.json b/test/getImportMapFromNodeModules/package-exports-field/exports-directory-scoped/root/package.json new file mode 100644 index 00000000..399e6ef7 --- /dev/null +++ b/test/getImportMapFromNodeModules/package-exports-field/exports-directory-scoped/root/package.json @@ -0,0 +1,6 @@ +{ + "name": "root", + "dependencies": { + "foo": "*" + } +} From 26f085a86627a445bf45c51b904bb8dae1ee108c Mon Sep 17 00:00:00 2001 From: Damien Maillard Date: Sat, 6 Mar 2021 18:11:26 +0100 Subject: [PATCH 07/36] Introduce dev/production conditions --- src/getImportMapFromNodeModules.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/getImportMapFromNodeModules.js b/src/getImportMapFromNodeModules.js index 0d593c0d..17c21bab 100644 --- a/src/getImportMapFromNodeModules.js +++ b/src/getImportMapFromNodeModules.js @@ -14,7 +14,11 @@ export const getImportMapFromNodeModules = async ({ await getImportMapFromPackages({ logLevel, projectDirectoryUrl, - packagesExportsPreference: ["import", ...(targetExportsPreferences[target] || [])], + packagesExportsPreference: [ + "import", + ...(targetExportsPreferences[target] || []), + ...(dev ? "development" : "production"), + ], projectPackageDevDependenciesIncluded: dev, ...rest, }), From 7463eec3ef6e5b3fbb9f4dabd087159d6cf85035 Mon Sep 17 00:00:00 2001 From: Damien Maillard Date: Sat, 6 Mar 2021 18:33:16 +0100 Subject: [PATCH 08/36] prepare parsing codebase for import --- .../codebase/getImportMapFromCodebase.js | 145 +++++++++++++++ .../codebase/parseSpecifiersFromFile.js | 3 +- .../codebase}/parseSpecifiersFromFile.test.js | 2 +- src/internal/codebase/showSource.js | 176 ++++++++++++++++++ 4 files changed, 324 insertions(+), 2 deletions(-) create mode 100644 src/internal/codebase/getImportMapFromCodebase.js rename {test => src/internal/codebase}/parseSpecifiersFromFile.test.js (94%) create mode 100644 src/internal/codebase/showSource.js diff --git a/src/internal/codebase/getImportMapFromCodebase.js b/src/internal/codebase/getImportMapFromCodebase.js new file mode 100644 index 00000000..e8c8b584 --- /dev/null +++ b/src/internal/codebase/getImportMapFromCodebase.js @@ -0,0 +1,145 @@ +/* + +IL SERAIT BIEN DE CONNAITRE TOUTES LES IMPORTMAPS +POUR PAS DIRE DE BETISES: +- que ce soit parce que un bare specifier n'a pas de remapping +-> on pourrait ne pas log de warning dans ce cas +mais c'est dommage + +- ou parce que on trouve pas un fichier (parce qu'il serait remap ailleurs sans etre un bare specifier) +-> use case rare mais pourquoi pas + +pour chaque bare specifier error +(donc pas dans importmap des node_modules) + +- s'il existe un fichier avec le meme nom + -> suggerer un remapping et lajouter de force +- si en ajoutant une extension + -> suggerer un remapping et l'ajouter de force +- sinon + -> suggerer que c'est une dépendance qu'il faut ajouter au package.json + non plutot un log de type debug + +si c'est pas un bare specifier et que le fichier est pas trouvé +- si magic extension + -> suggerer un remapping et l'ajouter de force +-> warning et puis c'est tout + +*/ + +import { createDetailedMessage } from "@jsenv/logger" +import { readFile, resolveUrl, urlToExtension } from "@jsenv/util" +// import { resolveImport } from "@jsenv/import-map" +import { memoizeAsyncFunctionByUrl } from "../memoizeAsyncFunctionByUrl.js" +import { parseSpecifiersFromFile } from "./parseSpecifiersFromFile.js" +import { showSource } from "./showSource.js" + +export const getImportMapFromCodebase = async ({ + logger, + projectDirectoryUrl, + magicExtensions = [".js", ".jsx", ".ts", ".tsx", ".node", ".json"], + target, + packagePreferences, +}) => { + const visitFile = async (specifier, importer, { importedIn }) => { + const fileUrl = await resolveUrl({ + specifier, + importer, + magicExtensions, + }) + + if (!fileUrl) { + logger.warn( + formatFileNotFoundLog({ + specifier, + importedIn, + magicExtensions, + }), + ) + return + } + + const fileContent = await readFileContent(fileUrl) + const specifiers = await parseSpecifiersFromFile(fileUrl, { fileContent }) + + await Promise.all( + Object.keys(specifiers).map(async (specifier) => { + const specifierInfo = specifiers[specifier] + await visitFile(specifier, fileUrl, { + importedIn: showSource({ + url: fileUrl, + line: specifierInfo.line, + column: specifierInfo.column, + source: fileContent, + }), + }) + }), + ) + } + const visitFileMemoized = memoizeAsyncFunctionByUrl(visitFile) + + const readFileContent = memoizeAsyncFunctionByUrl((fileUrl) => { + return readFile(fileUrl, { as: "string" }) + }) + + const rootPackageFileUrl = resolveUrl("package.json", projectDirectoryUrl) + const rootPackageObject = await readFileContent(rootPackageFileUrl) + const rootMainInfo = mainFromPackageObject({ + packageObject: rootPackageObject, + packageFileUrl: rootPackageFileUrl, + target, + packagePreferences, + }) + await visitFileMemoized(rootMainInfo.specifier, rootPackageFileUrl, { + importedIn: rootMainInfo.importedIn, + }) +} + +const mainFromPackageObject = ({ packageObject, packageFileUrl, target }) => { + // idéalement on lirait aussi package.exports + // pour y trouver le point d'entrée principal + // soit ".", soit la chaine directe + + if ("module" in packageObject) { + return { + specifier: packageObject.module, + importedIn: `${packageFileUrl}#module`, + } + } + + if ("jsnext:main" in packageObject) { + return { + specifier: packageObject["jsnext:main"], + importedIn: `${packageFileUrl}#jsnext:main`, + } + } + + if (target === "browser" && "browser" in packageObject) { + return { + specifier: packageObject.browser, + importedIn: `${packageFileUrl}#browser`, + } + } + + if ("main" in packageObject) { + return { + specifier: packageObject.main, + importedIn: `${packageFileUrl}#main`, + } + } + + return { + specifier: "index", + importedIn: `${packageFileUrl}#default`, + } +} + +const formatFileNotFoundLog = ({ specifier, expectedUrl, magicExtensions, importedIn }) => { + return createDetailedMessage(`Cannot find file for "${specifier}"`, { + "imported in": importedIn, + "file url": expectedUrl, + ...(urlToExtension(expectedUrl) === "" + ? { ["extensions tried"]: magicExtensions.join(`,`) } + : {}), + }) +} diff --git a/src/internal/codebase/parseSpecifiersFromFile.js b/src/internal/codebase/parseSpecifiersFromFile.js index 7964779c..140abadb 100644 --- a/src/internal/codebase/parseSpecifiersFromFile.js +++ b/src/internal/codebase/parseSpecifiersFromFile.js @@ -5,6 +5,7 @@ import { readFile, urlToFileSystemPath } from "@jsenv/util" export const parseSpecifiersFromFile = async ( fileUrl, { + fileContent, sourceType = "module", allowImportExportEverywhere = true, allowAwaitOutsideFunction = true, @@ -15,7 +16,7 @@ export const parseSpecifiersFromFile = async ( ...options } = {}, ) => { - const fileContent = await readFile(fileUrl, { as: "string" }) + fileContent = fileContent === undefined ? await readFile(fileUrl, { as: "string" }) : fileContent const ast = parser.parse(fileContent, { sourceType, diff --git a/test/parseSpecifiersFromFile.test.js b/src/internal/codebase/parseSpecifiersFromFile.test.js similarity index 94% rename from test/parseSpecifiersFromFile.test.js rename to src/internal/codebase/parseSpecifiersFromFile.test.js index 86acd2f9..bc4b999f 100644 --- a/test/parseSpecifiersFromFile.test.js +++ b/src/internal/codebase/parseSpecifiersFromFile.test.js @@ -1,4 +1,4 @@ -import { parseSpecifiersFromFile } from "../src/internal/codebase/parseSpecifiersFromFile.js" +import { parseSpecifiersFromFile } from "./parseSpecifiersFromFile.js" import { writeFile, ensureEmptyDirectory, resolveUrl } from "@jsenv/util" import { assert } from "@jsenv/assert" diff --git a/src/internal/codebase/showSource.js b/src/internal/codebase/showSource.js new file mode 100644 index 00000000..7e0b47a3 --- /dev/null +++ b/src/internal/codebase/showSource.js @@ -0,0 +1,176 @@ +// https://github.com/postcss/postcss/blob/fd30d3df5abc0954a0ec642a3cdc644ab2aacf9c/lib/css-syntax-error.js#L43 +// https://github.com/postcss/postcss/blob/fd30d3df5abc0954a0ec642a3cdc644ab2aacf9c/lib/terminal-highlight.js#L50 +// https://github.com/babel/babel/blob/eea156b2cb8deecfcf82d52aa1b71ba4995c7d68/packages/babel-code-frame/src/index.js#L1 + +export const showSource = ({ url, line, column, source }) => { + let message = "" + + message += typeof url === "undefined" ? "Anonymous" : url + if (typeof line !== "number") { + return message + } + + message += `:${line}` + if (typeof column === "number") { + message += `:${column}` + } + + if (!source) { + return message + } + + return `${message} + +${showSourceLocation(source, { + line, + column, +})} +` +} + +const red = "\x1b[31m" +const grey = "\x1b[39m" +const ansiResetSequence = "\x1b[0m" + +const showSourceLocation = ( + source, + { + line, + column, + numberOfSurroundingLinesToShow = 1, + lineMaxLength = 120, + color = false, + markColor = red, + asideColor = grey, + colorMark = (string) => `${markColor}${string}${ansiResetSequence}`, + colorAside = (string) => `${asideColor}${string}${ansiResetSequence}`, + }, +) => { + const mark = color ? colorMark : (string) => string + const aside = color ? colorAside : (string) => string + + const lines = source.split(/\r?\n/) + let lineRange = { + start: line - 1, + end: line, + } + lineRange = moveLineRangeUp(lineRange, numberOfSurroundingLinesToShow) + lineRange = moveLineRangeDown(lineRange, numberOfSurroundingLinesToShow) + lineRange = lineRangeWithinLines(lineRange, lines) + const linesToShow = lines.slice(lineRange.start, lineRange.end) + const endLineNumber = lineRange.end + const lineNumberMaxWidth = String(endLineNumber).length + + const columnRange = {} + if (column === undefined) { + columnRange.start = 0 + columnRange.end = lineMaxLength + } else if (column > lineMaxLength) { + columnRange.start = column - Math.floor(lineMaxLength / 2) + columnRange.end = column + Math.ceil(lineMaxLength / 2) + } else { + columnRange.start = 0 + columnRange.end = lineMaxLength + } + + return linesToShow.map((lineSource, index) => { + const lineNumber = lineRange.start + index + 1 + const isMainLine = lineNumber === line + const lineSourceTruncated = applyColumnRange(columnRange, lineSource) + const lineNumberWidth = String(lineNumber).length + // ensure if line moves from 7,8,9 to 10 the display is still great + const lineNumberRightSpacing = " ".repeat(lineNumberMaxWidth - lineNumberWidth) + const asideSource = `${lineNumber}${lineNumberRightSpacing} |` + const lineFormatted = `${aside(asideSource)} ${lineSourceTruncated}` + if (isMainLine) { + if (column === undefined) { + return `${mark(">")} ${lineFormatted}` + } + const spacing = stringToSpaces( + `${asideSource} ${lineSourceTruncated.slice(0, column - columnRange.start - 1)}`, + ) + return `${mark(">")} ${lineFormatted} + ${spacing}${mark("^")}` + } + return ` ${lineFormatted}` + }).join(` +`) +} + +const applyColumnRange = ({ start, end }, line) => { + if (typeof start !== "number") { + throw new TypeError(`start must be a number, received ${start}`) + } + if (typeof end !== "number") { + throw new TypeError(`end must be a number, received ${end}`) + } + if (end < start) { + throw new Error(`end must be greater than start, but ${end} is smaller than ${start}`) + } + + const prefix = "…" + const suffix = "…" + const lastIndex = line.length + + if (line.length === 0) { + // don't show any ellipsis if the line is empty + // because it's not truncated in that case + return "" + } + + const startTruncated = start > 0 + const endTruncated = lastIndex > end + + let from = startTruncated ? start + prefix.length : start + let to = endTruncated ? end - suffix.length : end + if (to > lastIndex) to = lastIndex + + if (start >= lastIndex || from === to) { + return "" + } + + let result = "" + while (from < to) { + result += line[from] + from++ + } + + if (result.length === 0) { + return "" + } + if (startTruncated && endTruncated) { + return `${prefix}${result}${suffix}` + } + if (startTruncated) { + return `${prefix}${result}` + } + if (endTruncated) { + return `${result}${suffix}` + } + return result +} + +const stringToSpaces = (string) => string.replace(/[^\t]/g, " ") + +// const getLineRangeLength = ({ start, end }) => end - start + +const moveLineRangeUp = ({ start, end }, number) => { + return { + start: start - number, + end, + } +} + +const moveLineRangeDown = ({ start, end }, number) => { + return { + start, + end: end + number, + } +} + +const lineRangeWithinLines = ({ start, end }, lines) => { + return { + start: start < 0 ? 0 : start, + end: end > lines.length ? lines.length : end, + } +} From cde78251fa2c3841be2ded8023e581577205b1f3 Mon Sep 17 00:00:00 2001 From: Damien Maillard Date: Sun, 7 Mar 2021 09:36:46 +0100 Subject: [PATCH 09/36] Remove package imports, we don't have a correct implementation, and not used for now. --- .../package/getImportMapFromPackages.js | 49 ------------- src/internal/package/visitPackageImports.js | 73 ------------------- .../imports-leading-slash.test.js | 22 ------ .../node_modules/foo/index.js | 0 .../node_modules/foo/package.json | 5 -- .../imports-leading-slash/package.json | 6 -- .../node_modules/project/index.js | 0 .../project/node_modules/inside/index.js | 0 .../project/node_modules/inside/package.json | 3 - .../node_modules/project/package.json | 10 --- .../node_modules/shared/index.js | 0 .../node_modules/shared/package.json | 3 - .../root-leading-slash/package.json | 5 -- .../root-leading-slash/root.test.js | 30 -------- 14 files changed, 206 deletions(-) delete mode 100644 src/internal/package/visitPackageImports.js delete mode 100644 test/getImportMapFromNodeModules/package-imports-field/imports-leading-slash/imports-leading-slash.test.js delete mode 100644 test/getImportMapFromNodeModules/package-imports-field/imports-leading-slash/node_modules/foo/index.js delete mode 100644 test/getImportMapFromNodeModules/package-imports-field/imports-leading-slash/node_modules/foo/package.json delete mode 100644 test/getImportMapFromNodeModules/package-imports-field/imports-leading-slash/package.json delete mode 100644 test/getImportMapFromNodeModules/package-imports-field/root-leading-slash/node_modules/project/index.js delete mode 100644 test/getImportMapFromNodeModules/package-imports-field/root-leading-slash/node_modules/project/node_modules/inside/index.js delete mode 100644 test/getImportMapFromNodeModules/package-imports-field/root-leading-slash/node_modules/project/node_modules/inside/package.json delete mode 100644 test/getImportMapFromNodeModules/package-imports-field/root-leading-slash/node_modules/project/package.json delete mode 100644 test/getImportMapFromNodeModules/package-imports-field/root-leading-slash/node_modules/shared/index.js delete mode 100644 test/getImportMapFromNodeModules/package-imports-field/root-leading-slash/node_modules/shared/package.json delete mode 100644 test/getImportMapFromNodeModules/package-imports-field/root-leading-slash/package.json delete mode 100644 test/getImportMapFromNodeModules/package-imports-field/root-leading-slash/root.test.js diff --git a/src/internal/package/getImportMapFromPackages.js b/src/internal/package/getImportMapFromPackages.js index c945383d..aac0daca 100644 --- a/src/internal/package/getImportMapFromPackages.js +++ b/src/internal/package/getImportMapFromPackages.js @@ -8,7 +8,6 @@ import { readFile, } from "@jsenv/util" import { resolvePackageMain } from "./resolvePackageMain.js" -import { visitPackageImports } from "./visitPackageImports.js" import { visitPackageExports } from "./visitPackageExports.js" import { createFindNodeModulePackage } from "./node-module-resolution.js" @@ -25,7 +24,6 @@ export const getImportMapFromPackages = async ({ packagesExportsPreference = ["import", "browser"], packagesExportsIncluded = true, packagesSelfReference = true, - packagesImportsIncluded = true, packagesManualOverrides = {}, packageIncludedPredicate = () => true, }) => { @@ -104,53 +102,6 @@ export const getImportMapFromPackages = async ({ packageInfo, }) - if (packagesImportsIncluded && "imports" in packageJsonObject) { - const importsForPackageImports = visitPackageImports({ - logger, - packageFileUrl, - packageName, - packageJsonObject, - packageInfo, - }) - - const { packageIsRoot, packageDirectoryRelativeUrl } = packageInfo - Object.keys(importsForPackageImports).forEach((from) => { - const to = importsForPackageImports[from] - - if (packageIsRoot) { - addTopLevelImportMapping({ from, to }) - } else { - const toScoped = - to[0] === "/" - ? to - : `./${packageDirectoryRelativeUrl}${to.startsWith("./") ? to.slice(2) : to}` - - addScopedImportMapping({ - scope: `./${packageDirectoryRelativeUrl}`, - from, - to: toScoped, - }) - - // when a package says './' maps to './' - // we must add something to say if we are already inside the package - // no need to ensure leading slash are scoped to the package - if (from === "./" && to === "./") { - addScopedImportMapping({ - scope: `./${packageDirectoryRelativeUrl}`, - from: `./${packageDirectoryRelativeUrl}`, - to: `./${packageDirectoryRelativeUrl}`, - }) - } else if (from === "/" && to === "/") { - addScopedImportMapping({ - scope: `./${packageDirectoryRelativeUrl}`, - from: `./${packageDirectoryRelativeUrl}`, - to: `./${packageDirectoryRelativeUrl}`, - }) - } - } - }) - } - if (packagesSelfReference) { const { packageIsRoot, packageDirectoryRelativeUrl } = packageInfo diff --git a/src/internal/package/visitPackageImports.js b/src/internal/package/visitPackageImports.js deleted file mode 100644 index b11f9b1d..00000000 --- a/src/internal/package/visitPackageImports.js +++ /dev/null @@ -1,73 +0,0 @@ -import { urlToFileSystemPath } from "@jsenv/util" -import { specifierIsRelative } from "./specifierIsRelative.js" - -export const visitPackageImports = ({ logger, packageFileUrl, packageJsonObject }) => { - const importsForPackageImports = {} - const packageFilePath = urlToFileSystemPath(packageFileUrl) - - const { imports: packageImports } = packageJsonObject - if (typeof packageImports !== "object" || packageImports === null) { - logger.warn(` -imports of package.json must be an object. ---- package.json imports --- -${packageImports} ---- package.json path --- -${packageFilePath} -`) - return importsForPackageImports - } - - Object.keys(packageImports).forEach((specifier) => { - if (!specifierIsRelative(specifier)) { - logger.warn(` -found unexpected specifier in imports of package.json, it must be relative to package.json. ---- specifier --- -${specifier} ---- package.json path --- -${packageFilePath} -`) - return - } - - const address = packageImports[specifier] - if (typeof address !== "string") { - logger.warn(` -found unexpected address in imports of package.json, it must be a string. ---- address --- -${address} ---- specifier --- -${specifier} ---- package.json path --- -${packageFilePath} -`) - return - } - if (!specifierIsRelative(address)) { - logger.warn(` -found unexpected address in imports of package.json, it must be relative to package.json. ---- address --- -${address} ---- specifier --- -${specifier} ---- package.json path --- -${packageFilePath} -`) - return - } - - let from - if (specifier[0] === "/") { - from = specifier - } else if (specifier.startsWith("./")) { - from = specifier - } else { - from = specifier - } - - const to = address - - importsForPackageImports[from] = to - }) - - return importsForPackageImports -} diff --git a/test/getImportMapFromNodeModules/package-imports-field/imports-leading-slash/imports-leading-slash.test.js b/test/getImportMapFromNodeModules/package-imports-field/imports-leading-slash/imports-leading-slash.test.js deleted file mode 100644 index df1751af..00000000 --- a/test/getImportMapFromNodeModules/package-imports-field/imports-leading-slash/imports-leading-slash.test.js +++ /dev/null @@ -1,22 +0,0 @@ -import { assert } from "@jsenv/assert" -import { resolveUrl } from "@jsenv/util" -import { getImportMapFromNodeModules } from "@jsenv/node-module-import-map" - -const testDirectoryUrl = resolveUrl("./", import.meta.url) - -const actual = await getImportMapFromNodeModules({ - projectDirectoryUrl: testDirectoryUrl, - packagesSelfReference: false, -}) -const expected = { - imports: { - foo: "./node_modules/foo/index.js", - }, - scopes: { - "./node_modules/foo/": { - "./node_modules/foo/": "./node_modules/foo/", - "./": "./node_modules/foo/", - }, - }, -} -assert({ actual, expected }) diff --git a/test/getImportMapFromNodeModules/package-imports-field/imports-leading-slash/node_modules/foo/index.js b/test/getImportMapFromNodeModules/package-imports-field/imports-leading-slash/node_modules/foo/index.js deleted file mode 100644 index e69de29b..00000000 diff --git a/test/getImportMapFromNodeModules/package-imports-field/imports-leading-slash/node_modules/foo/package.json b/test/getImportMapFromNodeModules/package-imports-field/imports-leading-slash/node_modules/foo/package.json deleted file mode 100644 index dabd1513..00000000 --- a/test/getImportMapFromNodeModules/package-imports-field/imports-leading-slash/node_modules/foo/package.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "imports": { - "./": "./" - } -} diff --git a/test/getImportMapFromNodeModules/package-imports-field/imports-leading-slash/package.json b/test/getImportMapFromNodeModules/package-imports-field/imports-leading-slash/package.json deleted file mode 100644 index 399e6ef7..00000000 --- a/test/getImportMapFromNodeModules/package-imports-field/imports-leading-slash/package.json +++ /dev/null @@ -1,6 +0,0 @@ -{ - "name": "root", - "dependencies": { - "foo": "*" - } -} diff --git a/test/getImportMapFromNodeModules/package-imports-field/root-leading-slash/node_modules/project/index.js b/test/getImportMapFromNodeModules/package-imports-field/root-leading-slash/node_modules/project/index.js deleted file mode 100644 index e69de29b..00000000 diff --git a/test/getImportMapFromNodeModules/package-imports-field/root-leading-slash/node_modules/project/node_modules/inside/index.js b/test/getImportMapFromNodeModules/package-imports-field/root-leading-slash/node_modules/project/node_modules/inside/index.js deleted file mode 100644 index e69de29b..00000000 diff --git a/test/getImportMapFromNodeModules/package-imports-field/root-leading-slash/node_modules/project/node_modules/inside/package.json b/test/getImportMapFromNodeModules/package-imports-field/root-leading-slash/node_modules/project/node_modules/inside/package.json deleted file mode 100644 index 8cb6129d..00000000 --- a/test/getImportMapFromNodeModules/package-imports-field/root-leading-slash/node_modules/project/node_modules/inside/package.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "name": "inside" -} diff --git a/test/getImportMapFromNodeModules/package-imports-field/root-leading-slash/node_modules/project/package.json b/test/getImportMapFromNodeModules/package-imports-field/root-leading-slash/node_modules/project/package.json deleted file mode 100644 index 50557336..00000000 --- a/test/getImportMapFromNodeModules/package-imports-field/root-leading-slash/node_modules/project/package.json +++ /dev/null @@ -1,10 +0,0 @@ -{ - "name": "project", - "dependencies": { - "shared": "*", - "inside": "*" - }, - "imports": { - "./": "./" - } -} diff --git a/test/getImportMapFromNodeModules/package-imports-field/root-leading-slash/node_modules/shared/index.js b/test/getImportMapFromNodeModules/package-imports-field/root-leading-slash/node_modules/shared/index.js deleted file mode 100644 index e69de29b..00000000 diff --git a/test/getImportMapFromNodeModules/package-imports-field/root-leading-slash/node_modules/shared/package.json b/test/getImportMapFromNodeModules/package-imports-field/root-leading-slash/node_modules/shared/package.json deleted file mode 100644 index 4aa31cb4..00000000 --- a/test/getImportMapFromNodeModules/package-imports-field/root-leading-slash/node_modules/shared/package.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "name": "shared" -} diff --git a/test/getImportMapFromNodeModules/package-imports-field/root-leading-slash/package.json b/test/getImportMapFromNodeModules/package-imports-field/root-leading-slash/package.json deleted file mode 100644 index 54a2dd4a..00000000 --- a/test/getImportMapFromNodeModules/package-imports-field/root-leading-slash/package.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "name": "root", - "type": "module", - "dependencies": {} -} diff --git a/test/getImportMapFromNodeModules/package-imports-field/root-leading-slash/root.test.js b/test/getImportMapFromNodeModules/package-imports-field/root-leading-slash/root.test.js deleted file mode 100644 index d93f76d0..00000000 --- a/test/getImportMapFromNodeModules/package-imports-field/root-leading-slash/root.test.js +++ /dev/null @@ -1,30 +0,0 @@ -import { assert } from "@jsenv/assert" -import { resolveUrl } from "@jsenv/util" -import { getImportMapFromNodeModules } from "@jsenv/node-module-import-map" - -const testDirectoryUrl = resolveUrl("./", import.meta.url) - -const actual = await getImportMapFromNodeModules({ - projectDirectoryUrl: `${testDirectoryUrl}node_modules/project`, - rootProjectDirectoryUrl: testDirectoryUrl, -}) -const expected = { - imports: {}, - scopes: { - "./node_modules/project/node_modules/inside/": { - "inside/": "./node_modules/project/node_modules/inside/", - }, - "./node_modules/project/": { - "./node_modules/project/": "./node_modules/project/", - "project/": "./node_modules/project/", - "project": "./node_modules/project/index.js", - "inside": "./node_modules/project/node_modules/inside/index.js", - "shared": "./node_modules/shared/index.js", - "./": "./node_modules/project/", - }, - "./node_modules/shared/": { - "shared/": "./node_modules/shared/", - }, - }, -} -assert({ actual, expected }) From 563b9d5ebcd6a961ca6c3c8eb2be9e552cb7f95c Mon Sep 17 00:00:00 2001 From: Damien Maillard Date: Sun, 7 Mar 2021 09:50:25 +0100 Subject: [PATCH 10/36] renamed main files --- readme.md | 2 +- src/getImportMapFromFile.js | 25 ++++++--- src/getImportMapFromNodeModules.js | 51 ------------------- src/getImportMapFromProjectFiles.js | 49 ++++++++++++++++++ ...Codebase.js => getImportMapFromJsFiles.js} | 2 +- ...ges.js => getImportMapFromPackageFiles.js} | 2 +- 6 files changed, 71 insertions(+), 60 deletions(-) delete mode 100644 src/getImportMapFromNodeModules.js create mode 100644 src/getImportMapFromProjectFiles.js rename src/internal/codebase/{getImportMapFromCodebase.js => getImportMapFromJsFiles.js} (98%) rename src/internal/package/{getImportMapFromPackages.js => getImportMapFromPackageFiles.js} (99%) diff --git a/readme.md b/readme.md index 47056558..2235a580 100644 --- a/readme.md +++ b/readme.md @@ -21,7 +21,7 @@ Generate importmap for node_modules. # Presentation -This repository generates [import map](https://github.com/WICG/import-maps) for node modules. The generated importmap can be used to make code dependent of node module executable in a browser. +This repository generates [import map](https://github.com/WICG/import-maps) from `package.json` files in your `node_modules` directory. The generated importmap can be used to make code dependent of node module executable in a browser.
See code relying on node module resolution diff --git a/src/getImportMapFromFile.js b/src/getImportMapFromFile.js index 2c13bf74..502fc044 100644 --- a/src/getImportMapFromFile.js +++ b/src/getImportMapFromFile.js @@ -1,8 +1,21 @@ -import { readFile, assertAndNormalizeFileUrl } from "@jsenv/util" +import { assertAndNormalizeDirectoryUrl, resolveUrl, readFile } from "@jsenv/util" +import { moveImportMap, sortImportMap } from "@jsenv/import-map" -export const getImportMapFromFile = async (importMapFilePath) => { - const importMapFileUrl = assertAndNormalizeFileUrl(importMapFilePath) - const importMapFileContent = await readFile(importMapFileUrl) - const importMap = JSON.parse(importMapFileContent) - return importMap +export const getImportMapFromFile = async ({ projectDirectoryUrl, importMapFileRelativeUrl }) => { + projectDirectoryUrl = assertAndNormalizeDirectoryUrl(projectDirectoryUrl) + + const importmapFileUrl = resolveUrl(importMapFileRelativeUrl, projectDirectoryUrl) + const importmap = await readFile(importmapFileUrl, { as: "json" }) + + // ensure the importmap is now relative to the project directory url + // we do that because generateImportMapForProject expect all importmap + // to be relative to the projectDirectoryUrl + const importmapFakeRootUrl = resolveUrl("whatever.importmap", projectDirectoryUrl) + const importmapRelativeToProject = moveImportMap( + importmap, + importmapFileUrl, + importmapFakeRootUrl, + ) + + return sortImportMap(importmapRelativeToProject) } diff --git a/src/getImportMapFromNodeModules.js b/src/getImportMapFromNodeModules.js deleted file mode 100644 index 17c21bab..00000000 --- a/src/getImportMapFromNodeModules.js +++ /dev/null @@ -1,51 +0,0 @@ -import { resolveUrl } from "@jsenv/util" -import { moveImportMap, sortImportMap } from "@jsenv/import-map" -import { getImportMapFromPackages } from "./internal/package/getImportMapFromPackages.js" - -export const getImportMapFromNodeModules = async ({ - logLevel, - projectDirectoryUrl, - importMapFileRelativeUrl, - target = "browser", - dev = false, - ...rest -}) => { - const importMapForPackages = moveAndSort( - await getImportMapFromPackages({ - logLevel, - projectDirectoryUrl, - packagesExportsPreference: [ - "import", - ...(targetExportsPreferences[target] || []), - ...(dev ? "development" : "production"), - ], - projectPackageDevDependenciesIncluded: dev, - ...rest, - }), - importMapFileRelativeUrl, - ) - - return importMapForPackages -} - -const targetExportsPreferences = { - browser: ["browser"], - node: ["node", "require"], -} - -const moveAndSort = (importmap, importMapFileRelativeUrl) => { - // At this point, importmap is relative to the project directory url - if (!importMapFileRelativeUrl) { - return sortImportMap(importmap) - } - - // When there is an importMapFileRelativeUrl we will make remapping relative - // to the importmap file future location (where user will write it). - // This allows to put the importmap anywhere inside the projectDirectoryUrl. - // If possible prefer top level because nesting importmap - // can lead to many relative path like ./file.js -> ../../file.js - const importMapProjectUrl = resolveUrl("project.importmap", "file://") - const importMapRealUrl = resolveUrl(importMapFileRelativeUrl, "file://") - const importmapMoved = moveImportMap(importmap, importMapProjectUrl, importMapRealUrl) - return sortImportMap(importmapMoved) -} diff --git a/src/getImportMapFromProjectFiles.js b/src/getImportMapFromProjectFiles.js new file mode 100644 index 00000000..1be16bed --- /dev/null +++ b/src/getImportMapFromProjectFiles.js @@ -0,0 +1,49 @@ +import { sortImportMap } from "@jsenv/import-map" +import { getImportMapFromPackageFiles } from "./internal/package/getImportMapFromPackageFiles.js" + +export const getImportMapFromProjectFiles = async ({ + logLevel, + projectDirectoryUrl, + target = "browser", + dev = false, + ...rest +}) => { + // At this point, importmap is relative to the project directory url + const importMapFromPackageFiles = sortImportMap( + await getImportMapFromPackageFiles({ + logLevel, + projectDirectoryUrl, + packagesExportsPreference: [ + "import", + ...(targetExportsPreferences[target] || []), + ...(dev ? "development" : "production"), + ], + projectPackageDevDependenciesIncluded: dev, + ...rest, + }), + ) + + return importMapFromPackageFiles +} + +const targetExportsPreferences = { + browser: ["browser"], + node: ["node", "require"], +} + +// const moveAndSort = (importmap, importMapFileRelativeUrl) => { +// // At this point, importmap is relative to the project directory url +// if (!importMapFileRelativeUrl) { +// return sortImportMap(importmap) +// } + +// // When there is an importMapFileRelativeUrl we will make remapping relative +// // to the importmap file future location (where user will write it). +// // This allows to put the importmap anywhere inside the projectDirectoryUrl. +// // If possible prefer top level because nesting importmap +// // can lead to many relative path like ./file.js -> ../../file.js +// const importMapProjectUrl = resolveUrl("project.importmap", "file://") +// const importMapRealUrl = resolveUrl(importMapFileRelativeUrl, "file://") +// const importmapMoved = moveImportMap(importmap, importMapProjectUrl, importMapRealUrl) +// return sortImportMap(importmapMoved) +// } diff --git a/src/internal/codebase/getImportMapFromCodebase.js b/src/internal/codebase/getImportMapFromJsFiles.js similarity index 98% rename from src/internal/codebase/getImportMapFromCodebase.js rename to src/internal/codebase/getImportMapFromJsFiles.js index e8c8b584..1d1ab797 100644 --- a/src/internal/codebase/getImportMapFromCodebase.js +++ b/src/internal/codebase/getImportMapFromJsFiles.js @@ -34,7 +34,7 @@ import { memoizeAsyncFunctionByUrl } from "../memoizeAsyncFunctionByUrl.js" import { parseSpecifiersFromFile } from "./parseSpecifiersFromFile.js" import { showSource } from "./showSource.js" -export const getImportMapFromCodebase = async ({ +export const getImportMapFromJsFiles = async ({ logger, projectDirectoryUrl, magicExtensions = [".js", ".jsx", ".ts", ".tsx", ".node", ".json"], diff --git a/src/internal/package/getImportMapFromPackages.js b/src/internal/package/getImportMapFromPackageFiles.js similarity index 99% rename from src/internal/package/getImportMapFromPackages.js rename to src/internal/package/getImportMapFromPackageFiles.js index aac0daca..6dd0b2bb 100644 --- a/src/internal/package/getImportMapFromPackages.js +++ b/src/internal/package/getImportMapFromPackageFiles.js @@ -11,7 +11,7 @@ import { resolvePackageMain } from "./resolvePackageMain.js" import { visitPackageExports } from "./visitPackageExports.js" import { createFindNodeModulePackage } from "./node-module-resolution.js" -export const getImportMapFromPackages = async ({ +export const getImportMapFromPackageFiles = async ({ // nothing is actually listening for this cancellationToken for now // it's not very important but it would be better to register on it // an stops what we are doing if asked to do so From 2b5206683cbe3381c809e49ef0ad550929bb999a Mon Sep 17 00:00:00 2001 From: Damien Maillard Date: Sun, 7 Mar 2021 10:15:42 +0100 Subject: [PATCH 11/36] renaming to make things clear, update doc --- docs/basic-project/generate-import-map.js | 4 +- index.js | 2 +- package.json | 2 +- readme.md | 108 ++++++------------ .../generate-import-map.js | 4 +- src/getImportMapFromProjectFiles.js | 8 +- .../getImportMapFromJsFiles.js | 0 .../parseSpecifiersFromFile.js | 0 .../parseSpecifiersFromFile.test.js | 0 .../{codebase => from-js}/showSource.js | 0 .../applyPackageManualOverride.js | 0 .../getImportMapFromPackageFiles.js | 0 .../node-module-resolution.js | 0 .../readPackageFile.js | 0 .../{package => from-package}/resolveFile.js | 0 .../resolveNodeModule.js | 0 .../resolvePackageMain.js | 0 .../specifierIsRelative.js | 0 .../visitPackageExports.js | 0 .../core/basic/basic.test.js | 4 +- .../core/basic/root/index.js | 0 .../root/node_modules/@dmail/yo/index.js | 0 .../root/node_modules/@dmail/yo/package.json | 0 .../core/basic/root/node_modules/bar/bar.js | 0 .../basic/root/node_modules/bar/package.json | 0 .../core/basic/root/node_modules/foo/foo.js | 0 .../foo/node_modules/bar/index.js | 0 .../foo/node_modules/bar/package.json | 0 .../basic/root/node_modules/foo/package.json | 0 .../core/basic/root/package.json | 0 .../core/circular/circular.test.js | 4 +- .../circular/root/node_modules/bar/bar.js | 0 .../root/node_modules/bar/package.json | 0 .../circular/root/node_modules/foo/foo.js | 0 .../root/node_modules/foo/package.json | 0 .../core/circular/root/package.json | 0 .../core/inside/inside.test.js | 4 +- .../core/inside/root/node_modules/bar/bar.js | 0 .../inside/root/node_modules/bar/package.json | 0 .../core/inside/root/node_modules/foo/foo.js | 0 .../node_modules/foo/node_modules/bar/bar.js | 0 .../foo/node_modules/bar/package.json | 0 .../inside/root/node_modules/foo/package.json | 0 .../core/inside/root/package.json | 0 .../core/issue-20/issue-20.test.js | 4 +- .../root/node_modules/lowclass/dist/index.js | 0 .../root/node_modules/lowclass/package.json | 0 .../issue-20/root/node_modules/lume/lume.js | 0 .../lume/node_modules/lowclass/dist/index.js | 0 .../lume/node_modules/lowclass/package.json | 0 .../root/node_modules/lume/package.json | 0 .../core/issue-20/root/package.json | 0 .../malformed-dependency-package.test.js | 4 +- .../root/node_modules/malformed/package.json | 0 .../root/package.json | 0 .../missing-dependency-package.test.js | 4 +- .../root/package.json | 0 .../missing-root-package.test.js | 4 +- .../optional-dependency.test.js | 4 +- .../optional-dependency/root/package.json | 0 .../@dmail/project-structure/package.json | 0 .../@dmail/project-structure/whatever.js | 0 .../node_modules/@jsenv/core/package.json | 0 .../node_modules/@jsenv/core/whatever.js | 0 .../node_modules/@jsenv/bundling/package.json | 0 .../node_modules/@jsenv/bundling/whatever.js | 0 .../scoped-inside-scoped/root/package.json | 0 .../scoped-inside-scoped.test.js | 4 +- .../root/node_modules/bar/bar.js | 0 .../root/node_modules/bar/package.json | 0 .../root/node_modules/foo/foo.js | 0 .../root/node_modules/foo/package.json | 0 .../core/shared-indirect/root/package.json | 0 .../shared-indirect/shared-indirect.test.js | 4 +- .../core/shared/root/node_modules/bar/bar.js | 0 .../shared/root/node_modules/bar/package.json | 0 .../core/shared/root/node_modules/foo/foo.js | 0 .../shared/root/node_modules/foo/package.json | 0 .../core/shared/root/package.json | 0 .../core/shared/shared.test.js | 4 +- .../core/sibling-and-deep/root/index.js | 0 .../nested/node_modules/bar/bar.js | 0 .../nested/node_modules/bar/package.json | 0 .../nested/node_modules/foo/foo.js | 0 .../nested/node_modules/foo/package.json | 0 .../root/node_modules/nested/package.json | 0 .../core/sibling-and-deep/root/package.json | 0 .../sibling-and-deep/sibling-and-deep.test.js | 4 +- .../core/symlink/root/index.js | 0 .../symlink/root/node_modules/foo/index.js | 0 .../root/node_modules/foo/package.json | 0 .../core/symlink/root/package.json | 0 .../core/symlink/root/project/index.js | 0 .../root/project/node_modules/foo/index.js | 0 .../project/node_modules/foo/package.json | 0 .../core/symlink/root/project/package.json | 0 .../core/symlink/symlink.test.js | 4 +- .../included-predicate.test.js | 4 +- .../root/node_modules/bar/package.json | 0 .../root/node_modules/foo/foo.js | 0 .../root/node_modules/foo/package.json | 0 .../included-predicate/root/package.json | 0 .../manual-override/manual-override.test.js | 4 +- .../manual-override/node_modules/bar/bar.js | 0 .../node_modules/bar/package.json | 0 .../manual-override/package.json | 0 .../exports-and-main/exports-and-main.test.js | 4 +- .../root/node_modules/foo/file.cjs | 0 .../root/node_modules/foo/index.js | 0 .../root/node_modules/foo/package.json | 0 .../exports-and-main/root/package.json | 0 .../exports-complex/exports-complex.test.js | 4 +- .../exports-complex/node_modules/foo/file.cjs | 0 .../node_modules/foo/package.json | 0 .../exports-complex/package.json | 0 .../exports-condition-nested.test.js | 6 +- .../root/node_modules/foo/package.json | 0 .../root/package.json | 0 .../exports-directory-scoped.test.js | 4 +- .../root/node_modules/foo/index.js | 0 .../node_modules/exporting-folder/index.js | 0 .../exporting-folder/package.json | 0 .../root/node_modules/foo/package.json | 0 .../root/package.json | 0 .../exports-directory.test.js | 4 +- .../node_modules/@jsenv/whatever/index.js | 0 .../node_modules/@jsenv/whatever/package.json | 0 .../exports-directory/package.json | 0 .../exports-file-conditional.test.js | 6 +- .../node_modules/foo/package.json | 0 .../exports-file-conditional/package.json | 0 .../exports-file-deep-2.test.js | 4 +- .../foo/node_modules/bar/package.json | 0 .../node_modules/foo/package.json | 0 .../exports-file-deep-2/package.json | 0 .../exports-file-deep.test.js | 4 +- .../node_modules/bar/package.json | 0 .../node_modules/foo/package.json | 0 .../exports-file-deep/package.json | 0 .../exports-file/exports-file.test.js | 4 +- .../exports-file/node_modules/foo/index.js | 0 .../node_modules/foo/package.json | 0 .../exports-file/package.json | 0 .../exports-pattern-directory.test.js | 4 +- .../node_modules/foo/package.json | 0 .../exports-pattern-directory/package.json | 0 .../exports-pattern-extensionless.test.js | 4 +- .../node_modules/foo/package.json | 0 .../package.json | 0 .../exports-string/exports-string.test.js | 4 +- .../node_modules/foo/package.json | 0 .../exports-string/package.json | 0 .../exports-sugar-conditional.test.js | 6 +- .../node_modules/foo/package.json | 0 .../exports-sugar-conditional/package.json | 0 .../exports-sugar/exports-sugar.test.js | 4 +- .../node_modules/foo/package.json | 0 .../exports-sugar/package.json | 0 .../main-directory-trailing.test.js | 4 +- .../main-folder-trailing/lib/index.js | 0 .../main-folder-trailing/package.json | 0 .../main-directory-trailing/package.json | 0 .../main-directory/main-directory.test.js | 4 +- .../node_modules/main-directory/lib/index.js | 0 .../node_modules/main-directory/package.json | 0 .../main-directory/package.json | 0 .../main-jsnext/main-jsnext.test.js | 4 +- .../node_modules/main-jsnext/jsnext.js | 0 .../node_modules/main-jsnext/package.json | 0 .../main-jsnext/package.json | 0 .../main-relative/main-relative.test.js | 4 +- .../node_modules/main-relative/lib/index.js | 0 .../node_modules/main-relative/package.json | 0 .../main-relative/package.json | 0 .../main-undefined/main-undefined.test.js | 4 +- .../node_modules/main-undefined/index.js | 0 .../node_modules/main-undefined/package.json | 0 .../main-undefined/package.json | 0 .../main-without-extension.test.js | 4 +- .../main-without-extension/file.js | 0 .../main-without-extension/package.json | 0 .../main-without-extension/root/package.json | 0 .../self-import/self-import-1/index.js | 0 .../self-import/self-import-1/package.json | 0 .../self-import-1/self-import.test.js | 4 +- .../self-import/self-import-2/index.js | 0 .../self-import-2/node_modules/foo/index.js | 0 .../node_modules/foo/package.json | 0 .../self-import/self-import-2/package.json | 0 .../self-import-2/self-import-2.test.js | 4 +- .../self-import/self-import-3/index.js | 0 .../node_modules/foo/package.json | 0 .../self-import/self-import-3/package.json | 0 .../self-import-3/self-import-3.test.js | 4 +- .../self-import/self-import-4/index.js | 0 .../node_modules/@jsenv/core/package.json | 0 .../self-import/self-import-4/package.json | 0 .../self-import-4/self-import-4.test.js | 4 +- .../node_modules/@jsenv/core/package.json | 0 .../self-import/self-import-5/package.json | 0 .../self-import-5/self-import-5.test.js | 4 +- .../node_modules/@jsenv/core/package.json | 0 .../self-import-6/root/package.json | 0 .../self-import-6/self-import-6.test.js | 4 +- 204 files changed, 130 insertions(+), 168 deletions(-) rename src/internal/{codebase => from-js}/getImportMapFromJsFiles.js (100%) rename src/internal/{codebase => from-js}/parseSpecifiersFromFile.js (100%) rename src/internal/{codebase => from-js}/parseSpecifiersFromFile.test.js (100%) rename src/internal/{codebase => from-js}/showSource.js (100%) rename src/internal/{package => from-package}/applyPackageManualOverride.js (100%) rename src/internal/{package => from-package}/getImportMapFromPackageFiles.js (100%) rename src/internal/{package => from-package}/node-module-resolution.js (100%) rename src/internal/{package => from-package}/readPackageFile.js (100%) rename src/internal/{package => from-package}/resolveFile.js (100%) rename src/internal/{package => from-package}/resolveNodeModule.js (100%) rename src/internal/{package => from-package}/resolvePackageMain.js (100%) rename src/internal/{package => from-package}/specifierIsRelative.js (100%) rename src/internal/{package => from-package}/visitPackageExports.js (100%) rename test/{getImportMapFromNodeModules => getImportMapFromProjectFiles}/core/basic/basic.test.js (86%) rename test/{getImportMapFromNodeModules => getImportMapFromProjectFiles}/core/basic/root/index.js (100%) rename test/{getImportMapFromNodeModules => getImportMapFromProjectFiles}/core/basic/root/node_modules/@dmail/yo/index.js (100%) rename test/{getImportMapFromNodeModules => getImportMapFromProjectFiles}/core/basic/root/node_modules/@dmail/yo/package.json (100%) rename test/{getImportMapFromNodeModules => getImportMapFromProjectFiles}/core/basic/root/node_modules/bar/bar.js (100%) rename test/{getImportMapFromNodeModules => getImportMapFromProjectFiles}/core/basic/root/node_modules/bar/package.json (100%) rename test/{getImportMapFromNodeModules => getImportMapFromProjectFiles}/core/basic/root/node_modules/foo/foo.js (100%) rename test/{getImportMapFromNodeModules => getImportMapFromProjectFiles}/core/basic/root/node_modules/foo/node_modules/bar/index.js (100%) rename test/{getImportMapFromNodeModules => getImportMapFromProjectFiles}/core/basic/root/node_modules/foo/node_modules/bar/package.json (100%) rename test/{getImportMapFromNodeModules => getImportMapFromProjectFiles}/core/basic/root/node_modules/foo/package.json (100%) rename test/{getImportMapFromNodeModules => getImportMapFromProjectFiles}/core/basic/root/package.json (100%) rename test/{getImportMapFromNodeModules => getImportMapFromProjectFiles}/core/circular/circular.test.js (74%) rename test/{getImportMapFromNodeModules => getImportMapFromProjectFiles}/core/circular/root/node_modules/bar/bar.js (100%) rename test/{getImportMapFromNodeModules => getImportMapFromProjectFiles}/core/circular/root/node_modules/bar/package.json (100%) rename test/{getImportMapFromNodeModules => getImportMapFromProjectFiles}/core/circular/root/node_modules/foo/foo.js (100%) rename test/{getImportMapFromNodeModules => getImportMapFromProjectFiles}/core/circular/root/node_modules/foo/package.json (100%) rename test/{getImportMapFromNodeModules => getImportMapFromProjectFiles}/core/circular/root/package.json (100%) rename test/{getImportMapFromNodeModules => getImportMapFromProjectFiles}/core/inside/inside.test.js (92%) rename test/{getImportMapFromNodeModules => getImportMapFromProjectFiles}/core/inside/root/node_modules/bar/bar.js (100%) rename test/{getImportMapFromNodeModules => getImportMapFromProjectFiles}/core/inside/root/node_modules/bar/package.json (100%) rename test/{getImportMapFromNodeModules => getImportMapFromProjectFiles}/core/inside/root/node_modules/foo/foo.js (100%) rename test/{getImportMapFromNodeModules => getImportMapFromProjectFiles}/core/inside/root/node_modules/foo/node_modules/bar/bar.js (100%) rename test/{getImportMapFromNodeModules => getImportMapFromProjectFiles}/core/inside/root/node_modules/foo/node_modules/bar/package.json (100%) rename test/{getImportMapFromNodeModules => getImportMapFromProjectFiles}/core/inside/root/node_modules/foo/package.json (100%) rename test/{getImportMapFromNodeModules => getImportMapFromProjectFiles}/core/inside/root/package.json (100%) rename test/{getImportMapFromNodeModules => getImportMapFromProjectFiles}/core/issue-20/issue-20.test.js (89%) rename test/{getImportMapFromNodeModules => getImportMapFromProjectFiles}/core/issue-20/root/node_modules/lowclass/dist/index.js (100%) rename test/{getImportMapFromNodeModules => getImportMapFromProjectFiles}/core/issue-20/root/node_modules/lowclass/package.json (100%) rename test/{getImportMapFromNodeModules => getImportMapFromProjectFiles}/core/issue-20/root/node_modules/lume/lume.js (100%) rename test/{getImportMapFromNodeModules => getImportMapFromProjectFiles}/core/issue-20/root/node_modules/lume/node_modules/lowclass/dist/index.js (100%) rename test/{getImportMapFromNodeModules => getImportMapFromProjectFiles}/core/issue-20/root/node_modules/lume/node_modules/lowclass/package.json (100%) rename test/{getImportMapFromNodeModules => getImportMapFromProjectFiles}/core/issue-20/root/node_modules/lume/package.json (100%) rename test/{getImportMapFromNodeModules => getImportMapFromProjectFiles}/core/issue-20/root/package.json (100%) rename test/{getImportMapFromNodeModules => getImportMapFromProjectFiles}/core/malformed-dependency-package/malformed-dependency-package.test.js (74%) rename test/{getImportMapFromNodeModules => getImportMapFromProjectFiles}/core/malformed-dependency-package/root/node_modules/malformed/package.json (100%) rename test/{getImportMapFromNodeModules => getImportMapFromProjectFiles}/core/malformed-dependency-package/root/package.json (100%) rename test/{getImportMapFromNodeModules => getImportMapFromProjectFiles}/core/missing-dependency-package/missing-dependency-package.test.js (71%) rename test/{getImportMapFromNodeModules => getImportMapFromProjectFiles}/core/missing-dependency-package/root/package.json (100%) rename test/{getImportMapFromNodeModules => getImportMapFromProjectFiles}/core/missing-root-package/missing-root-package.test.js (84%) rename test/{getImportMapFromNodeModules => getImportMapFromProjectFiles}/core/optional-dependency/optional-dependency.test.js (70%) rename test/{getImportMapFromNodeModules => getImportMapFromProjectFiles}/core/optional-dependency/root/package.json (100%) rename test/{getImportMapFromNodeModules => getImportMapFromProjectFiles}/core/scoped-inside-scoped/root/node_modules/@jsenv/bundling/node_modules/@jsenv/core/node_modules/@dmail/project-structure/package.json (100%) rename test/{getImportMapFromNodeModules => getImportMapFromProjectFiles}/core/scoped-inside-scoped/root/node_modules/@jsenv/bundling/node_modules/@jsenv/core/node_modules/@dmail/project-structure/whatever.js (100%) rename test/{getImportMapFromNodeModules => getImportMapFromProjectFiles}/core/scoped-inside-scoped/root/node_modules/@jsenv/bundling/node_modules/@jsenv/core/package.json (100%) rename test/{getImportMapFromNodeModules => getImportMapFromProjectFiles}/core/scoped-inside-scoped/root/node_modules/@jsenv/bundling/node_modules/@jsenv/core/whatever.js (100%) rename test/{getImportMapFromNodeModules => getImportMapFromProjectFiles}/core/scoped-inside-scoped/root/node_modules/@jsenv/bundling/package.json (100%) rename test/{getImportMapFromNodeModules => getImportMapFromProjectFiles}/core/scoped-inside-scoped/root/node_modules/@jsenv/bundling/whatever.js (100%) rename test/{getImportMapFromNodeModules => getImportMapFromProjectFiles}/core/scoped-inside-scoped/root/package.json (100%) rename test/{getImportMapFromNodeModules => getImportMapFromProjectFiles}/core/scoped-inside-scoped/scoped-inside-scoped.test.js (85%) rename test/{getImportMapFromNodeModules => getImportMapFromProjectFiles}/core/shared-indirect/root/node_modules/bar/bar.js (100%) rename test/{getImportMapFromNodeModules => getImportMapFromProjectFiles}/core/shared-indirect/root/node_modules/bar/package.json (100%) rename test/{getImportMapFromNodeModules => getImportMapFromProjectFiles}/core/shared-indirect/root/node_modules/foo/foo.js (100%) rename test/{getImportMapFromNodeModules => getImportMapFromProjectFiles}/core/shared-indirect/root/node_modules/foo/package.json (100%) rename test/{getImportMapFromNodeModules => getImportMapFromProjectFiles}/core/shared-indirect/root/package.json (100%) rename test/{getImportMapFromNodeModules => getImportMapFromProjectFiles}/core/shared-indirect/shared-indirect.test.js (89%) rename test/{getImportMapFromNodeModules => getImportMapFromProjectFiles}/core/shared/root/node_modules/bar/bar.js (100%) rename test/{getImportMapFromNodeModules => getImportMapFromProjectFiles}/core/shared/root/node_modules/bar/package.json (100%) rename test/{getImportMapFromNodeModules => getImportMapFromProjectFiles}/core/shared/root/node_modules/foo/foo.js (100%) rename test/{getImportMapFromNodeModules => getImportMapFromProjectFiles}/core/shared/root/node_modules/foo/package.json (100%) rename test/{getImportMapFromNodeModules => getImportMapFromProjectFiles}/core/shared/root/package.json (100%) rename test/{getImportMapFromNodeModules => getImportMapFromProjectFiles}/core/shared/shared.test.js (94%) rename test/{getImportMapFromNodeModules => getImportMapFromProjectFiles}/core/sibling-and-deep/root/index.js (100%) rename test/{getImportMapFromNodeModules => getImportMapFromProjectFiles}/core/sibling-and-deep/root/node_modules/nested/node_modules/bar/bar.js (100%) rename test/{getImportMapFromNodeModules => getImportMapFromProjectFiles}/core/sibling-and-deep/root/node_modules/nested/node_modules/bar/package.json (100%) rename test/{getImportMapFromNodeModules => getImportMapFromProjectFiles}/core/sibling-and-deep/root/node_modules/nested/node_modules/foo/foo.js (100%) rename test/{getImportMapFromNodeModules => getImportMapFromProjectFiles}/core/sibling-and-deep/root/node_modules/nested/node_modules/foo/package.json (100%) rename test/{getImportMapFromNodeModules => getImportMapFromProjectFiles}/core/sibling-and-deep/root/node_modules/nested/package.json (100%) rename test/{getImportMapFromNodeModules => getImportMapFromProjectFiles}/core/sibling-and-deep/root/package.json (100%) rename test/{getImportMapFromNodeModules => getImportMapFromProjectFiles}/core/sibling-and-deep/sibling-and-deep.test.js (86%) rename test/{getImportMapFromNodeModules => getImportMapFromProjectFiles}/core/symlink/root/index.js (100%) rename test/{getImportMapFromNodeModules => getImportMapFromProjectFiles}/core/symlink/root/node_modules/foo/index.js (100%) rename test/{getImportMapFromNodeModules => getImportMapFromProjectFiles}/core/symlink/root/node_modules/foo/package.json (100%) rename test/{getImportMapFromNodeModules => getImportMapFromProjectFiles}/core/symlink/root/package.json (100%) rename test/{getImportMapFromNodeModules => getImportMapFromProjectFiles}/core/symlink/root/project/index.js (100%) rename test/{getImportMapFromNodeModules => getImportMapFromProjectFiles}/core/symlink/root/project/node_modules/foo/index.js (100%) rename test/{getImportMapFromNodeModules => getImportMapFromProjectFiles}/core/symlink/root/project/node_modules/foo/package.json (100%) rename test/{getImportMapFromNodeModules => getImportMapFromProjectFiles}/core/symlink/root/project/package.json (100%) rename test/{getImportMapFromNodeModules => getImportMapFromProjectFiles}/core/symlink/symlink.test.js (80%) rename test/{getImportMapFromNodeModules => getImportMapFromProjectFiles}/included-predicate/included-predicate.test.js (76%) rename test/{getImportMapFromNodeModules => getImportMapFromProjectFiles}/included-predicate/root/node_modules/bar/package.json (100%) rename test/{getImportMapFromNodeModules => getImportMapFromProjectFiles}/included-predicate/root/node_modules/foo/foo.js (100%) rename test/{getImportMapFromNodeModules => getImportMapFromProjectFiles}/included-predicate/root/node_modules/foo/package.json (100%) rename test/{getImportMapFromNodeModules => getImportMapFromProjectFiles}/included-predicate/root/package.json (100%) rename test/{getImportMapFromNodeModules => getImportMapFromProjectFiles}/manual-override/manual-override.test.js (79%) rename test/{getImportMapFromNodeModules => getImportMapFromProjectFiles}/manual-override/node_modules/bar/bar.js (100%) rename test/{getImportMapFromNodeModules => getImportMapFromProjectFiles}/manual-override/node_modules/bar/package.json (100%) rename test/{getImportMapFromNodeModules => getImportMapFromProjectFiles}/manual-override/package.json (100%) rename test/{getImportMapFromNodeModules => getImportMapFromProjectFiles}/package-exports-field/exports-and-main/exports-and-main.test.js (72%) rename test/{getImportMapFromNodeModules => getImportMapFromProjectFiles}/package-exports-field/exports-and-main/root/node_modules/foo/file.cjs (100%) rename test/{getImportMapFromNodeModules => getImportMapFromProjectFiles}/package-exports-field/exports-and-main/root/node_modules/foo/index.js (100%) rename test/{getImportMapFromNodeModules => getImportMapFromProjectFiles}/package-exports-field/exports-and-main/root/node_modules/foo/package.json (100%) rename test/{getImportMapFromNodeModules => getImportMapFromProjectFiles}/package-exports-field/exports-and-main/root/package.json (100%) rename test/{getImportMapFromNodeModules => getImportMapFromProjectFiles}/package-exports-field/exports-complex/exports-complex.test.js (92%) rename test/{getImportMapFromNodeModules => getImportMapFromProjectFiles}/package-exports-field/exports-complex/node_modules/foo/file.cjs (100%) rename test/{getImportMapFromNodeModules => getImportMapFromProjectFiles}/package-exports-field/exports-complex/node_modules/foo/package.json (100%) rename test/{getImportMapFromNodeModules => getImportMapFromProjectFiles}/package-exports-field/exports-complex/package.json (100%) rename test/{getImportMapFromNodeModules => getImportMapFromProjectFiles}/package-exports-field/exports-condition-nested/exports-condition-nested.test.js (78%) rename test/{getImportMapFromNodeModules => getImportMapFromProjectFiles}/package-exports-field/exports-condition-nested/root/node_modules/foo/package.json (100%) rename test/{getImportMapFromNodeModules => getImportMapFromProjectFiles}/package-exports-field/exports-condition-nested/root/package.json (100%) rename test/{getImportMapFromNodeModules => getImportMapFromProjectFiles}/package-exports-field/exports-directory-scoped/exports-directory-scoped.test.js (85%) rename test/{getImportMapFromNodeModules => getImportMapFromProjectFiles}/package-exports-field/exports-directory-scoped/root/node_modules/foo/index.js (100%) rename test/{getImportMapFromNodeModules => getImportMapFromProjectFiles}/package-exports-field/exports-directory-scoped/root/node_modules/foo/node_modules/exporting-folder/index.js (100%) rename test/{getImportMapFromNodeModules => getImportMapFromProjectFiles}/package-exports-field/exports-directory-scoped/root/node_modules/foo/node_modules/exporting-folder/package.json (100%) rename test/{getImportMapFromNodeModules => getImportMapFromProjectFiles}/package-exports-field/exports-directory-scoped/root/node_modules/foo/package.json (100%) rename test/{getImportMapFromNodeModules => getImportMapFromProjectFiles}/package-exports-field/exports-directory-scoped/root/package.json (100%) rename test/{getImportMapFromNodeModules => getImportMapFromProjectFiles}/package-exports-field/exports-directory/exports-directory.test.js (76%) rename test/{getImportMapFromNodeModules => getImportMapFromProjectFiles}/package-exports-field/exports-directory/node_modules/@jsenv/whatever/index.js (100%) rename test/{getImportMapFromNodeModules => getImportMapFromProjectFiles}/package-exports-field/exports-directory/node_modules/@jsenv/whatever/package.json (100%) rename test/{getImportMapFromNodeModules => getImportMapFromProjectFiles}/package-exports-field/exports-directory/package.json (100%) rename test/{getImportMapFromNodeModules => getImportMapFromProjectFiles}/package-exports-field/exports-file-conditional/exports-file-conditional.test.js (81%) rename test/{getImportMapFromNodeModules => getImportMapFromProjectFiles}/package-exports-field/exports-file-conditional/node_modules/foo/package.json (100%) rename test/{getImportMapFromNodeModules => getImportMapFromProjectFiles}/package-exports-field/exports-file-conditional/package.json (100%) rename test/{getImportMapFromNodeModules => getImportMapFromProjectFiles}/package-exports-field/exports-file-deep-2/exports-file-deep-2.test.js (83%) rename test/{getImportMapFromNodeModules => getImportMapFromProjectFiles}/package-exports-field/exports-file-deep-2/node_modules/foo/node_modules/bar/package.json (100%) rename test/{getImportMapFromNodeModules => getImportMapFromProjectFiles}/package-exports-field/exports-file-deep-2/node_modules/foo/package.json (100%) rename test/{getImportMapFromNodeModules => getImportMapFromProjectFiles}/package-exports-field/exports-file-deep-2/package.json (100%) rename test/{getImportMapFromNodeModules => getImportMapFromProjectFiles}/package-exports-field/exports-file-deep/exports-file-deep.test.js (81%) rename test/{getImportMapFromNodeModules => getImportMapFromProjectFiles}/package-exports-field/exports-file-deep/node_modules/bar/package.json (100%) rename test/{getImportMapFromNodeModules => getImportMapFromProjectFiles}/package-exports-field/exports-file-deep/node_modules/foo/package.json (100%) rename test/{getImportMapFromNodeModules => getImportMapFromProjectFiles}/package-exports-field/exports-file-deep/package.json (100%) rename test/{getImportMapFromNodeModules => getImportMapFromProjectFiles}/package-exports-field/exports-file/exports-file.test.js (76%) rename test/{getImportMapFromNodeModules => getImportMapFromProjectFiles}/package-exports-field/exports-file/node_modules/foo/index.js (100%) rename test/{getImportMapFromNodeModules => getImportMapFromProjectFiles}/package-exports-field/exports-file/node_modules/foo/package.json (100%) rename test/{getImportMapFromNodeModules => getImportMapFromProjectFiles}/package-exports-field/exports-file/package.json (100%) rename test/{getImportMapFromNodeModules => getImportMapFromProjectFiles}/package-exports-field/exports-pattern-directory/exports-pattern-directory.test.js (74%) rename test/{getImportMapFromNodeModules => getImportMapFromProjectFiles}/package-exports-field/exports-pattern-directory/node_modules/foo/package.json (100%) rename test/{getImportMapFromNodeModules => getImportMapFromProjectFiles}/package-exports-field/exports-pattern-directory/package.json (100%) rename test/{getImportMapFromNodeModules => getImportMapFromProjectFiles}/package-exports-field/exports-pattern-extensionless/exports-pattern-extensionless.test.js (72%) rename test/{getImportMapFromNodeModules => getImportMapFromProjectFiles}/package-exports-field/exports-pattern-extensionless/node_modules/foo/package.json (100%) rename test/{getImportMapFromNodeModules => getImportMapFromProjectFiles}/package-exports-field/exports-pattern-extensionless/package.json (100%) rename test/{getImportMapFromNodeModules => getImportMapFromProjectFiles}/package-exports-field/exports-string/exports-string.test.js (73%) rename test/{getImportMapFromNodeModules => getImportMapFromProjectFiles}/package-exports-field/exports-string/node_modules/foo/package.json (100%) rename test/{getImportMapFromNodeModules => getImportMapFromProjectFiles}/package-exports-field/exports-string/package.json (100%) rename test/{getImportMapFromNodeModules => getImportMapFromProjectFiles}/package-exports-field/exports-sugar-conditional/exports-sugar-conditional.test.js (79%) rename test/{getImportMapFromNodeModules => getImportMapFromProjectFiles}/package-exports-field/exports-sugar-conditional/node_modules/foo/package.json (100%) rename test/{getImportMapFromNodeModules => getImportMapFromProjectFiles}/package-exports-field/exports-sugar-conditional/package.json (100%) rename test/{getImportMapFromNodeModules => getImportMapFromProjectFiles}/package-exports-field/exports-sugar/exports-sugar.test.js (73%) rename test/{getImportMapFromNodeModules => getImportMapFromProjectFiles}/package-exports-field/exports-sugar/node_modules/foo/package.json (100%) rename test/{getImportMapFromNodeModules => getImportMapFromProjectFiles}/package-exports-field/exports-sugar/package.json (100%) rename test/{getImportMapFromNodeModules => getImportMapFromProjectFiles}/package-main-field/main-directory-trailing/main-directory-trailing.test.js (74%) rename test/{getImportMapFromNodeModules => getImportMapFromProjectFiles}/package-main-field/main-directory-trailing/node_modules/main-folder-trailing/lib/index.js (100%) rename test/{getImportMapFromNodeModules => getImportMapFromProjectFiles}/package-main-field/main-directory-trailing/node_modules/main-folder-trailing/package.json (100%) rename test/{getImportMapFromNodeModules => getImportMapFromProjectFiles}/package-main-field/main-directory-trailing/package.json (100%) rename test/{getImportMapFromNodeModules => getImportMapFromProjectFiles}/package-main-field/main-directory/main-directory.test.js (73%) rename test/{getImportMapFromNodeModules => getImportMapFromProjectFiles}/package-main-field/main-directory/node_modules/main-directory/lib/index.js (100%) rename test/{getImportMapFromNodeModules => getImportMapFromProjectFiles}/package-main-field/main-directory/node_modules/main-directory/package.json (100%) rename test/{getImportMapFromNodeModules => getImportMapFromProjectFiles}/package-main-field/main-directory/package.json (100%) rename test/{getImportMapFromNodeModules => getImportMapFromProjectFiles}/package-main-field/main-jsnext/main-jsnext.test.js (73%) rename test/{getImportMapFromNodeModules => getImportMapFromProjectFiles}/package-main-field/main-jsnext/node_modules/main-jsnext/jsnext.js (100%) rename test/{getImportMapFromNodeModules => getImportMapFromProjectFiles}/package-main-field/main-jsnext/node_modules/main-jsnext/package.json (100%) rename test/{getImportMapFromNodeModules => getImportMapFromProjectFiles}/package-main-field/main-jsnext/package.json (100%) rename test/{getImportMapFromNodeModules => getImportMapFromProjectFiles}/package-main-field/main-relative/main-relative.test.js (73%) rename test/{getImportMapFromNodeModules => getImportMapFromProjectFiles}/package-main-field/main-relative/node_modules/main-relative/lib/index.js (100%) rename test/{getImportMapFromNodeModules => getImportMapFromProjectFiles}/package-main-field/main-relative/node_modules/main-relative/package.json (100%) rename test/{getImportMapFromNodeModules => getImportMapFromProjectFiles}/package-main-field/main-relative/package.json (100%) rename test/{getImportMapFromNodeModules => getImportMapFromProjectFiles}/package-main-field/main-undefined/main-undefined.test.js (73%) rename test/{getImportMapFromNodeModules => getImportMapFromProjectFiles}/package-main-field/main-undefined/node_modules/main-undefined/index.js (100%) rename test/{getImportMapFromNodeModules => getImportMapFromProjectFiles}/package-main-field/main-undefined/node_modules/main-undefined/package.json (100%) rename test/{getImportMapFromNodeModules => getImportMapFromProjectFiles}/package-main-field/main-undefined/package.json (100%) rename test/{getImportMapFromNodeModules => getImportMapFromProjectFiles}/package-main-field/main-without-extension/main-without-extension.test.js (74%) rename test/{getImportMapFromNodeModules => getImportMapFromProjectFiles}/package-main-field/main-without-extension/root/node_modules/main-without-extension/file.js (100%) rename test/{getImportMapFromNodeModules => getImportMapFromProjectFiles}/package-main-field/main-without-extension/root/node_modules/main-without-extension/package.json (100%) rename test/{getImportMapFromNodeModules => getImportMapFromProjectFiles}/package-main-field/main-without-extension/root/package.json (100%) rename test/{getImportMapFromNodeModules => getImportMapFromProjectFiles}/self-import/self-import-1/index.js (100%) rename test/{getImportMapFromNodeModules => getImportMapFromProjectFiles}/self-import/self-import-1/package.json (100%) rename test/{getImportMapFromNodeModules => getImportMapFromProjectFiles}/self-import/self-import-1/self-import.test.js (70%) rename test/{getImportMapFromNodeModules => getImportMapFromProjectFiles}/self-import/self-import-2/index.js (100%) rename test/{getImportMapFromNodeModules => getImportMapFromProjectFiles}/self-import/self-import-2/node_modules/foo/index.js (100%) rename test/{getImportMapFromNodeModules => getImportMapFromProjectFiles}/self-import/self-import-2/node_modules/foo/package.json (100%) rename test/{getImportMapFromNodeModules => getImportMapFromProjectFiles}/self-import/self-import-2/package.json (100%) rename test/{getImportMapFromNodeModules => getImportMapFromProjectFiles}/self-import/self-import-2/self-import-2.test.js (76%) rename test/{getImportMapFromNodeModules => getImportMapFromProjectFiles}/self-import/self-import-3/index.js (100%) rename test/{getImportMapFromNodeModules => getImportMapFromProjectFiles}/self-import/self-import-3/node_modules/foo/package.json (100%) rename test/{getImportMapFromNodeModules => getImportMapFromProjectFiles}/self-import/self-import-3/package.json (100%) rename test/{getImportMapFromNodeModules => getImportMapFromProjectFiles}/self-import/self-import-3/self-import-3.test.js (78%) rename test/{getImportMapFromNodeModules => getImportMapFromProjectFiles}/self-import/self-import-4/index.js (100%) rename test/{getImportMapFromNodeModules => getImportMapFromProjectFiles}/self-import/self-import-4/node_modules/@jsenv/core/package.json (100%) rename test/{getImportMapFromNodeModules => getImportMapFromProjectFiles}/self-import/self-import-4/package.json (100%) rename test/{getImportMapFromNodeModules => getImportMapFromProjectFiles}/self-import/self-import-4/self-import-4.test.js (78%) rename test/{getImportMapFromNodeModules => getImportMapFromProjectFiles}/self-import/self-import-5/node_modules/@jsenv/core/package.json (100%) rename test/{getImportMapFromNodeModules => getImportMapFromProjectFiles}/self-import/self-import-5/package.json (100%) rename test/{getImportMapFromNodeModules => getImportMapFromProjectFiles}/self-import/self-import-5/self-import-5.test.js (78%) rename test/{getImportMapFromNodeModules => getImportMapFromProjectFiles}/self-import/self-import-6/root/node_modules/@jsenv/core/package.json (100%) rename test/{getImportMapFromNodeModules => getImportMapFromProjectFiles}/self-import/self-import-6/root/package.json (100%) rename test/{getImportMapFromNodeModules => getImportMapFromProjectFiles}/self-import/self-import-6/self-import-6.test.js (85%) diff --git a/docs/basic-project/generate-import-map.js b/docs/basic-project/generate-import-map.js index c8104472..01e490a2 100644 --- a/docs/basic-project/generate-import-map.js +++ b/docs/basic-project/generate-import-map.js @@ -1,6 +1,6 @@ -import { getImportMapFromNodeModules } from "@jsenv/node-module-import-map" +import { getImportMapFromProjectFiles } from "@jsenv/node-module-import-map" -getImportMapFromNodeModules({ +getImportMapFromProjectFiles({ projectDirectoryUrl: new URL("./", import.meta.url), projectPackageDevDependenciesIncluded: true, importMapFileRelativeUrl: "./import-map.importmap", diff --git a/index.js b/index.js index 1ccc4656..5368c3cb 100644 --- a/index.js +++ b/index.js @@ -1,3 +1,3 @@ -export { getImportMapFromNodeModules } from "./src/getImportMapFromNodeModules.js" +export { getImportMapFromProjectFiles } from "./src/getImportMapFromProjectFiles.js" export { getImportMapFromFile } from "./src/getImportMapFromFile.js" export { generateImportMapForProject } from "./src/generateImportMapForProject.js" diff --git a/package.json b/package.json index 1a5891a4..974aec1d 100644 --- a/package.json +++ b/package.json @@ -28,9 +28,9 @@ "/index.js" ], "scripts": { + "eslint-check": "node ./node_modules/eslint/bin/eslint.js .", "test": "node ./script/test/test.js", "test-with-coverage": "npm run test -- --coverage", - "eslint-check": "node ./node_modules/eslint/bin/eslint.js .", "prettier-format": "node ./script/prettier-format/prettier-format.js", "prettier-format-stage": "npm run prettier-format -- --staged", "prettier-check": "npm run prettier-format -- --dry-run", diff --git a/readme.md b/readme.md index 2235a580..c3ec5c90 100644 --- a/readme.md +++ b/readme.md @@ -14,7 +14,7 @@ Generate importmap for node_modules. - [Extensionless import warning](#Extensionless-import-warning) - [Subpath import warning](#Subpath-import-warning) - [generateImportMapForProject](#generateImportMapForProject) -- [getImportMapFromNodeModules](#getImportMapFromNodeModules) +- [getImportMapFromProjectFiles](#getImportMapFromProjectFiles) - [getImportMapFromFile](#getImportMapFromFile) - [Custom node module resolution](#custom-node-module-resolution) - [Concrete example](#concrete-example) @@ -60,7 +60,7 @@ const projectDirectoryUrl = new URL("./", import.meta.url) await generateImportMapForProject( [ - getImportMapFromNodeModules({ + getImportMapFromProjectFiles({ projectDirectoryUrl, }), ], @@ -84,7 +84,7 @@ const projectDirectoryUrl = __dirname await generateImportMapForProject( [ - getImportMapFromNodeModules({ + getImportMapFromProjectFiles({ projectDirectoryUrl, }), ], @@ -239,19 +239,21 @@ Code below generate an import map from node_modules + a file + an inline importm ```js import { - getImportMapFromNodeModules, + getImportMapFromProjectFiles, getImportMapFromFile, generateImportMapForProject, } from "@jsenv/node-module-import-map" const projectDirectoryUrl = new URL("./", import.meta.url) -const customImportMapFileUrl = new URL("./import-map-custom.importmap", projectDirectoryUrl) const importMapInputs = [ - getImportMapFromNodeModules({ + getImportMapFromProjectFiles({ + projectDirectoryUrl, + dev: true, + }), + getImportMapFromFile({ projectDirectoryUrl, - projectPackageDevDependenciesIncluded: true, + importMapFileRelativeUrl: "./import-map-custom.importmap", }), - getImportMapFromFile(customImportMapFileUrl), { imports: { foo: "./bar.js", @@ -283,25 +285,25 @@ await generateImportMapForProject(importMapInputs, { `importMapFileRelativeUrl` parameter is a string controlling where importMap file is written. This parameter is optional and by default it's `"./import-map.importmap"`. -# getImportMapFromNodeModules +# getImportMapFromProjectFiles -`getImportMapFromNodeModules` is an async function returning an importMap object computed from the content of node_modules directory. It reads your project `package.json` and recursively try to find your dependencies. - -> Be sure node modules are on your filesystem because we'll use the filesystem structure to generate the importmap. For that reason, you must use it after `npm install` or anything that is responsible to generate the node_modules folder and its content on your filesystem. +`getImportMapFromProjectFiles` is an async function returning an importMap object computed from infos found in `package.json` files and js files. Your `package.json`, your js files and all the one found in `node_modules` directory are used.
- getImportMapFromNodeModules code example + getImportMapFromProjectFiles code example ```js -import { getImportMapFromNodeModules } from "@jsenv/node-module-import-map" +import { getImportMapFromProjectFiles } from "@jsenv/node-module-import-map" -const importMap = await getImportMapFromNodeModules({ +const importMap = await getImportMapFromProjectFiles({ projectDirectoryUrl: new URL("./", import.meta.url), - projectPackageDevDependenciesIncluded: true, + dev: true, }) ``` -— source code at [src/getImportMapFromNodeModules.js](./src/getImportMapFromNodeModules.js) +> Be sure node modules are on your filesystem because we'll use the filesystem structure to generate the importmap. For that reason, you must use it after `npm install` or anything that is responsible to generate the node_modules folder and its content on your filesystem. + +— source code at [src/getImportMapFromProjectFiles.js](./src/getImportMapFromProjectFiles.js)
@@ -309,64 +311,22 @@ const importMap = await getImportMapFromNodeModules({ `projectDirectoryUrl` parameter is a string url leading to a folder with a `package.json`. This parameters is **required** and accepted values are documented in https://github.com/jsenv/jsenv-util#assertandnormalizedirectoryurl -## projectPackageDevDependenciesIncluded +## dev -`projectPackageDevDependenciesIncluded` parameter is a boolean controling if devDependencies from your project `package.json` are included in the generated importMap. This parameter is optional and by default it's disabled when `process.env.NODE_ENV` is `"production"`. +`dev` parameter is a boolean indicating if the importmap will be used for development or production. This parameter is optional and by default it's disabled. -## packagesExportsPreference +When enabled the following happens: -`packagesExportsPreference` parameter is an array of string representing what conditional export you prefer to pick from package.json. This parameter is optional with a default value of `["import", "browser"]`. +1. Your `package.json` `devDependencies` are included in the generated importMap. +2. `"development"` is favored over `"production"` in [package.json exports conditions](https://nodejs.org/dist/latest-v15.x/docs/api/packages.html#packages_conditions_definitions). -It exists to support [conditional exports from Node.js](https://nodejs.org/dist/latest-v13.x/docs/api/esm.html#esm_conditional_exports). +## runtime -
- package.json with conditional exports +`runtime` parameter is a string indicating where the importmap will be used. This parameter is optional with a default of `"browser"`. -```json -{ - "type": "module", - "main": "dist/commonjs/main.cjs", - "exports": { - ".": { - "require": "./dist/main.cjs", - "browser": "./main.browser.js", - "node": "./main.node.js", - "import": "./main.node.js" - } - } -} -``` - -
- -When none of `packagesExportsPreference` is found in a `package.json` and if `"default"` is specified in that `package.json`, `"default"` value is read and appears in the importmap. - -
- packagesExportsPreference code example +When `runtime` is `"browser"`, `"browser"` is favored over `"node"` in [package.json exports conditions](https://nodejs.org/dist/latest-v15.x/docs/api/packages.html#packages_conditions_definitions). -Favoring `"browser"` export: - -```js -import { getImportMapFromNodeModules } from "@jsenv/node-module-import-map" - -const importMap = await getImportMapFromNodeModules({ - projectDirectoryUrl: new URL("./", import.meta.url), - packagesExportsPreference: ["browser"], -}) -``` - -Favoring `"electron"` and fallback to `"browser"`: - -```js -import { getImportMapFromNodeModules } from "@jsenv/node-module-import-map" - -const importMap = await getImportMapFromNodeModules({ - projectDirectoryUrl: new URL("./", import.meta.url), - packagesExportsPreference: ["electron", "browser"], -}) -``` - -
+When it is `"node"`, `"node"` is favored. # getImportMapFromFile @@ -378,17 +338,19 @@ const importMap = await getImportMapFromNodeModules({ ```js import { getImportMapFromFile } from "@jsenv/node-module-import-map" -const importMapFileUrl = new URL("./import-map.importmap", import.meta.url) -const importMap = await getImportMapFromFile(importMapFileUrl) +const importMap = await getImportMapFromFile({ + projectDirectoryUrl: new URL("./", import.meta.url), + importMapRelativeUrl: "./import-map.importmap", +}) ``` -— source code at [src/getImportMapFromFile.js](../src/getImportMapFromFile.js) +— source code at [src/getImportMapFromFile.js](./src/getImportMapFromFile.js)
-## importMapFileUrl +## importMapFileRelativeUrl -`importMapFileUrl` parameter a string or an url leading to the importmap file. This parameter is **required**. +`importMapFileUrl` parameter an url relative to [projectDirectoryUrl](#projectDirectoryUrl) leading to the importmap file. This parameter is **required**. # Custom node module resolution diff --git a/script/generate-import-map/generate-import-map.js b/script/generate-import-map/generate-import-map.js index 20c5cacd..0185613e 100644 --- a/script/generate-import-map/generate-import-map.js +++ b/script/generate-import-map/generate-import-map.js @@ -1,12 +1,12 @@ import { - getImportMapFromNodeModules, + getImportMapFromProjectFiles, generateImportMapForProject, } from "@jsenv/node-module-import-map" import { projectDirectoryUrl, importMapFileRelativeUrl } from "../../jsenv.config.js" generateImportMapForProject( [ - getImportMapFromNodeModules({ + getImportMapFromProjectFiles({ projectDirectoryUrl, target: "node", dev: true, diff --git a/src/getImportMapFromProjectFiles.js b/src/getImportMapFromProjectFiles.js index 1be16bed..3d6b1601 100644 --- a/src/getImportMapFromProjectFiles.js +++ b/src/getImportMapFromProjectFiles.js @@ -1,10 +1,10 @@ import { sortImportMap } from "@jsenv/import-map" -import { getImportMapFromPackageFiles } from "./internal/package/getImportMapFromPackageFiles.js" +import { getImportMapFromPackageFiles } from "./internal/from-package/getImportMapFromPackageFiles.js" export const getImportMapFromProjectFiles = async ({ logLevel, projectDirectoryUrl, - target = "browser", + runtime = "browser", dev = false, ...rest }) => { @@ -15,7 +15,7 @@ export const getImportMapFromProjectFiles = async ({ projectDirectoryUrl, packagesExportsPreference: [ "import", - ...(targetExportsPreferences[target] || []), + ...(runtimeExportsPreferences[runtime] || [runtime]), ...(dev ? "development" : "production"), ], projectPackageDevDependenciesIncluded: dev, @@ -26,7 +26,7 @@ export const getImportMapFromProjectFiles = async ({ return importMapFromPackageFiles } -const targetExportsPreferences = { +const runtimeExportsPreferences = { browser: ["browser"], node: ["node", "require"], } diff --git a/src/internal/codebase/getImportMapFromJsFiles.js b/src/internal/from-js/getImportMapFromJsFiles.js similarity index 100% rename from src/internal/codebase/getImportMapFromJsFiles.js rename to src/internal/from-js/getImportMapFromJsFiles.js diff --git a/src/internal/codebase/parseSpecifiersFromFile.js b/src/internal/from-js/parseSpecifiersFromFile.js similarity index 100% rename from src/internal/codebase/parseSpecifiersFromFile.js rename to src/internal/from-js/parseSpecifiersFromFile.js diff --git a/src/internal/codebase/parseSpecifiersFromFile.test.js b/src/internal/from-js/parseSpecifiersFromFile.test.js similarity index 100% rename from src/internal/codebase/parseSpecifiersFromFile.test.js rename to src/internal/from-js/parseSpecifiersFromFile.test.js diff --git a/src/internal/codebase/showSource.js b/src/internal/from-js/showSource.js similarity index 100% rename from src/internal/codebase/showSource.js rename to src/internal/from-js/showSource.js diff --git a/src/internal/package/applyPackageManualOverride.js b/src/internal/from-package/applyPackageManualOverride.js similarity index 100% rename from src/internal/package/applyPackageManualOverride.js rename to src/internal/from-package/applyPackageManualOverride.js diff --git a/src/internal/package/getImportMapFromPackageFiles.js b/src/internal/from-package/getImportMapFromPackageFiles.js similarity index 100% rename from src/internal/package/getImportMapFromPackageFiles.js rename to src/internal/from-package/getImportMapFromPackageFiles.js diff --git a/src/internal/package/node-module-resolution.js b/src/internal/from-package/node-module-resolution.js similarity index 100% rename from src/internal/package/node-module-resolution.js rename to src/internal/from-package/node-module-resolution.js diff --git a/src/internal/package/readPackageFile.js b/src/internal/from-package/readPackageFile.js similarity index 100% rename from src/internal/package/readPackageFile.js rename to src/internal/from-package/readPackageFile.js diff --git a/src/internal/package/resolveFile.js b/src/internal/from-package/resolveFile.js similarity index 100% rename from src/internal/package/resolveFile.js rename to src/internal/from-package/resolveFile.js diff --git a/src/internal/package/resolveNodeModule.js b/src/internal/from-package/resolveNodeModule.js similarity index 100% rename from src/internal/package/resolveNodeModule.js rename to src/internal/from-package/resolveNodeModule.js diff --git a/src/internal/package/resolvePackageMain.js b/src/internal/from-package/resolvePackageMain.js similarity index 100% rename from src/internal/package/resolvePackageMain.js rename to src/internal/from-package/resolvePackageMain.js diff --git a/src/internal/package/specifierIsRelative.js b/src/internal/from-package/specifierIsRelative.js similarity index 100% rename from src/internal/package/specifierIsRelative.js rename to src/internal/from-package/specifierIsRelative.js diff --git a/src/internal/package/visitPackageExports.js b/src/internal/from-package/visitPackageExports.js similarity index 100% rename from src/internal/package/visitPackageExports.js rename to src/internal/from-package/visitPackageExports.js diff --git a/test/getImportMapFromNodeModules/core/basic/basic.test.js b/test/getImportMapFromProjectFiles/core/basic/basic.test.js similarity index 86% rename from test/getImportMapFromNodeModules/core/basic/basic.test.js rename to test/getImportMapFromProjectFiles/core/basic/basic.test.js index ccfcdd20..55592d76 100644 --- a/test/getImportMapFromNodeModules/core/basic/basic.test.js +++ b/test/getImportMapFromProjectFiles/core/basic/basic.test.js @@ -1,10 +1,10 @@ import { assert } from "@jsenv/assert" import { resolveUrl } from "@jsenv/util" -import { getImportMapFromNodeModules } from "@jsenv/node-module-import-map" +import { getImportMapFromProjectFiles } from "@jsenv/node-module-import-map" const testDirectoryUrl = resolveUrl("./root/", import.meta.url) -const actual = await getImportMapFromNodeModules({ +const actual = await getImportMapFromProjectFiles({ projectDirectoryUrl: testDirectoryUrl, }) const expected = { diff --git a/test/getImportMapFromNodeModules/core/basic/root/index.js b/test/getImportMapFromProjectFiles/core/basic/root/index.js similarity index 100% rename from test/getImportMapFromNodeModules/core/basic/root/index.js rename to test/getImportMapFromProjectFiles/core/basic/root/index.js diff --git a/test/getImportMapFromNodeModules/core/basic/root/node_modules/@dmail/yo/index.js b/test/getImportMapFromProjectFiles/core/basic/root/node_modules/@dmail/yo/index.js similarity index 100% rename from test/getImportMapFromNodeModules/core/basic/root/node_modules/@dmail/yo/index.js rename to test/getImportMapFromProjectFiles/core/basic/root/node_modules/@dmail/yo/index.js diff --git a/test/getImportMapFromNodeModules/core/basic/root/node_modules/@dmail/yo/package.json b/test/getImportMapFromProjectFiles/core/basic/root/node_modules/@dmail/yo/package.json similarity index 100% rename from test/getImportMapFromNodeModules/core/basic/root/node_modules/@dmail/yo/package.json rename to test/getImportMapFromProjectFiles/core/basic/root/node_modules/@dmail/yo/package.json diff --git a/test/getImportMapFromNodeModules/core/basic/root/node_modules/bar/bar.js b/test/getImportMapFromProjectFiles/core/basic/root/node_modules/bar/bar.js similarity index 100% rename from test/getImportMapFromNodeModules/core/basic/root/node_modules/bar/bar.js rename to test/getImportMapFromProjectFiles/core/basic/root/node_modules/bar/bar.js diff --git a/test/getImportMapFromNodeModules/core/basic/root/node_modules/bar/package.json b/test/getImportMapFromProjectFiles/core/basic/root/node_modules/bar/package.json similarity index 100% rename from test/getImportMapFromNodeModules/core/basic/root/node_modules/bar/package.json rename to test/getImportMapFromProjectFiles/core/basic/root/node_modules/bar/package.json diff --git a/test/getImportMapFromNodeModules/core/basic/root/node_modules/foo/foo.js b/test/getImportMapFromProjectFiles/core/basic/root/node_modules/foo/foo.js similarity index 100% rename from test/getImportMapFromNodeModules/core/basic/root/node_modules/foo/foo.js rename to test/getImportMapFromProjectFiles/core/basic/root/node_modules/foo/foo.js diff --git a/test/getImportMapFromNodeModules/core/basic/root/node_modules/foo/node_modules/bar/index.js b/test/getImportMapFromProjectFiles/core/basic/root/node_modules/foo/node_modules/bar/index.js similarity index 100% rename from test/getImportMapFromNodeModules/core/basic/root/node_modules/foo/node_modules/bar/index.js rename to test/getImportMapFromProjectFiles/core/basic/root/node_modules/foo/node_modules/bar/index.js diff --git a/test/getImportMapFromNodeModules/core/basic/root/node_modules/foo/node_modules/bar/package.json b/test/getImportMapFromProjectFiles/core/basic/root/node_modules/foo/node_modules/bar/package.json similarity index 100% rename from test/getImportMapFromNodeModules/core/basic/root/node_modules/foo/node_modules/bar/package.json rename to test/getImportMapFromProjectFiles/core/basic/root/node_modules/foo/node_modules/bar/package.json diff --git a/test/getImportMapFromNodeModules/core/basic/root/node_modules/foo/package.json b/test/getImportMapFromProjectFiles/core/basic/root/node_modules/foo/package.json similarity index 100% rename from test/getImportMapFromNodeModules/core/basic/root/node_modules/foo/package.json rename to test/getImportMapFromProjectFiles/core/basic/root/node_modules/foo/package.json diff --git a/test/getImportMapFromNodeModules/core/basic/root/package.json b/test/getImportMapFromProjectFiles/core/basic/root/package.json similarity index 100% rename from test/getImportMapFromNodeModules/core/basic/root/package.json rename to test/getImportMapFromProjectFiles/core/basic/root/package.json diff --git a/test/getImportMapFromNodeModules/core/circular/circular.test.js b/test/getImportMapFromProjectFiles/core/circular/circular.test.js similarity index 74% rename from test/getImportMapFromNodeModules/core/circular/circular.test.js rename to test/getImportMapFromProjectFiles/core/circular/circular.test.js index 627c3dd9..ccf4aeed 100644 --- a/test/getImportMapFromNodeModules/core/circular/circular.test.js +++ b/test/getImportMapFromProjectFiles/core/circular/circular.test.js @@ -1,10 +1,10 @@ import { assert } from "@jsenv/assert" import { resolveUrl } from "@jsenv/util" -import { getImportMapFromNodeModules } from "@jsenv/node-module-import-map" +import { getImportMapFromProjectFiles } from "@jsenv/node-module-import-map" const testDirectoryUrl = resolveUrl("./root/", import.meta.url) -const actual = await getImportMapFromNodeModules({ +const actual = await getImportMapFromProjectFiles({ projectDirectoryUrl: testDirectoryUrl, packagesSelfReference: false, }) diff --git a/test/getImportMapFromNodeModules/core/circular/root/node_modules/bar/bar.js b/test/getImportMapFromProjectFiles/core/circular/root/node_modules/bar/bar.js similarity index 100% rename from test/getImportMapFromNodeModules/core/circular/root/node_modules/bar/bar.js rename to test/getImportMapFromProjectFiles/core/circular/root/node_modules/bar/bar.js diff --git a/test/getImportMapFromNodeModules/core/circular/root/node_modules/bar/package.json b/test/getImportMapFromProjectFiles/core/circular/root/node_modules/bar/package.json similarity index 100% rename from test/getImportMapFromNodeModules/core/circular/root/node_modules/bar/package.json rename to test/getImportMapFromProjectFiles/core/circular/root/node_modules/bar/package.json diff --git a/test/getImportMapFromNodeModules/core/circular/root/node_modules/foo/foo.js b/test/getImportMapFromProjectFiles/core/circular/root/node_modules/foo/foo.js similarity index 100% rename from test/getImportMapFromNodeModules/core/circular/root/node_modules/foo/foo.js rename to test/getImportMapFromProjectFiles/core/circular/root/node_modules/foo/foo.js diff --git a/test/getImportMapFromNodeModules/core/circular/root/node_modules/foo/package.json b/test/getImportMapFromProjectFiles/core/circular/root/node_modules/foo/package.json similarity index 100% rename from test/getImportMapFromNodeModules/core/circular/root/node_modules/foo/package.json rename to test/getImportMapFromProjectFiles/core/circular/root/node_modules/foo/package.json diff --git a/test/getImportMapFromNodeModules/core/circular/root/package.json b/test/getImportMapFromProjectFiles/core/circular/root/package.json similarity index 100% rename from test/getImportMapFromNodeModules/core/circular/root/package.json rename to test/getImportMapFromProjectFiles/core/circular/root/package.json diff --git a/test/getImportMapFromNodeModules/core/inside/inside.test.js b/test/getImportMapFromProjectFiles/core/inside/inside.test.js similarity index 92% rename from test/getImportMapFromNodeModules/core/inside/inside.test.js rename to test/getImportMapFromProjectFiles/core/inside/inside.test.js index b15fb246..5647c411 100644 --- a/test/getImportMapFromNodeModules/core/inside/inside.test.js +++ b/test/getImportMapFromProjectFiles/core/inside/inside.test.js @@ -1,11 +1,11 @@ import { resolveImport, normalizeImportMap } from "@jsenv/import-map" import { assert } from "@jsenv/assert" import { resolveUrl } from "@jsenv/util" -import { getImportMapFromNodeModules } from "@jsenv/node-module-import-map" +import { getImportMapFromProjectFiles } from "@jsenv/node-module-import-map" const testDirectoryUrl = resolveUrl("./root/", import.meta.url) -const importMap = await getImportMapFromNodeModules({ +const importMap = await getImportMapFromProjectFiles({ projectDirectoryUrl: testDirectoryUrl, packagesSelfReference: false, }) diff --git a/test/getImportMapFromNodeModules/core/inside/root/node_modules/bar/bar.js b/test/getImportMapFromProjectFiles/core/inside/root/node_modules/bar/bar.js similarity index 100% rename from test/getImportMapFromNodeModules/core/inside/root/node_modules/bar/bar.js rename to test/getImportMapFromProjectFiles/core/inside/root/node_modules/bar/bar.js diff --git a/test/getImportMapFromNodeModules/core/inside/root/node_modules/bar/package.json b/test/getImportMapFromProjectFiles/core/inside/root/node_modules/bar/package.json similarity index 100% rename from test/getImportMapFromNodeModules/core/inside/root/node_modules/bar/package.json rename to test/getImportMapFromProjectFiles/core/inside/root/node_modules/bar/package.json diff --git a/test/getImportMapFromNodeModules/core/inside/root/node_modules/foo/foo.js b/test/getImportMapFromProjectFiles/core/inside/root/node_modules/foo/foo.js similarity index 100% rename from test/getImportMapFromNodeModules/core/inside/root/node_modules/foo/foo.js rename to test/getImportMapFromProjectFiles/core/inside/root/node_modules/foo/foo.js diff --git a/test/getImportMapFromNodeModules/core/inside/root/node_modules/foo/node_modules/bar/bar.js b/test/getImportMapFromProjectFiles/core/inside/root/node_modules/foo/node_modules/bar/bar.js similarity index 100% rename from test/getImportMapFromNodeModules/core/inside/root/node_modules/foo/node_modules/bar/bar.js rename to test/getImportMapFromProjectFiles/core/inside/root/node_modules/foo/node_modules/bar/bar.js diff --git a/test/getImportMapFromNodeModules/core/inside/root/node_modules/foo/node_modules/bar/package.json b/test/getImportMapFromProjectFiles/core/inside/root/node_modules/foo/node_modules/bar/package.json similarity index 100% rename from test/getImportMapFromNodeModules/core/inside/root/node_modules/foo/node_modules/bar/package.json rename to test/getImportMapFromProjectFiles/core/inside/root/node_modules/foo/node_modules/bar/package.json diff --git a/test/getImportMapFromNodeModules/core/inside/root/node_modules/foo/package.json b/test/getImportMapFromProjectFiles/core/inside/root/node_modules/foo/package.json similarity index 100% rename from test/getImportMapFromNodeModules/core/inside/root/node_modules/foo/package.json rename to test/getImportMapFromProjectFiles/core/inside/root/node_modules/foo/package.json diff --git a/test/getImportMapFromNodeModules/core/inside/root/package.json b/test/getImportMapFromProjectFiles/core/inside/root/package.json similarity index 100% rename from test/getImportMapFromNodeModules/core/inside/root/package.json rename to test/getImportMapFromProjectFiles/core/inside/root/package.json diff --git a/test/getImportMapFromNodeModules/core/issue-20/issue-20.test.js b/test/getImportMapFromProjectFiles/core/issue-20/issue-20.test.js similarity index 89% rename from test/getImportMapFromNodeModules/core/issue-20/issue-20.test.js rename to test/getImportMapFromProjectFiles/core/issue-20/issue-20.test.js index 2f1a4604..2ff0f8a7 100644 --- a/test/getImportMapFromNodeModules/core/issue-20/issue-20.test.js +++ b/test/getImportMapFromProjectFiles/core/issue-20/issue-20.test.js @@ -1,11 +1,11 @@ import { normalizeImportMap, resolveImport } from "@jsenv/import-map" import { resolveUrl } from "@jsenv/util" import { assert } from "@jsenv/assert" -import { getImportMapFromNodeModules } from "@jsenv/node-module-import-map" +import { getImportMapFromProjectFiles } from "@jsenv/node-module-import-map" const testDirectoryUrl = resolveUrl("./root/", import.meta.url) -const importMap = await getImportMapFromNodeModules({ +const importMap = await getImportMapFromProjectFiles({ projectDirectoryUrl: testDirectoryUrl, }) { diff --git a/test/getImportMapFromNodeModules/core/issue-20/root/node_modules/lowclass/dist/index.js b/test/getImportMapFromProjectFiles/core/issue-20/root/node_modules/lowclass/dist/index.js similarity index 100% rename from test/getImportMapFromNodeModules/core/issue-20/root/node_modules/lowclass/dist/index.js rename to test/getImportMapFromProjectFiles/core/issue-20/root/node_modules/lowclass/dist/index.js diff --git a/test/getImportMapFromNodeModules/core/issue-20/root/node_modules/lowclass/package.json b/test/getImportMapFromProjectFiles/core/issue-20/root/node_modules/lowclass/package.json similarity index 100% rename from test/getImportMapFromNodeModules/core/issue-20/root/node_modules/lowclass/package.json rename to test/getImportMapFromProjectFiles/core/issue-20/root/node_modules/lowclass/package.json diff --git a/test/getImportMapFromNodeModules/core/issue-20/root/node_modules/lume/lume.js b/test/getImportMapFromProjectFiles/core/issue-20/root/node_modules/lume/lume.js similarity index 100% rename from test/getImportMapFromNodeModules/core/issue-20/root/node_modules/lume/lume.js rename to test/getImportMapFromProjectFiles/core/issue-20/root/node_modules/lume/lume.js diff --git a/test/getImportMapFromNodeModules/core/issue-20/root/node_modules/lume/node_modules/lowclass/dist/index.js b/test/getImportMapFromProjectFiles/core/issue-20/root/node_modules/lume/node_modules/lowclass/dist/index.js similarity index 100% rename from test/getImportMapFromNodeModules/core/issue-20/root/node_modules/lume/node_modules/lowclass/dist/index.js rename to test/getImportMapFromProjectFiles/core/issue-20/root/node_modules/lume/node_modules/lowclass/dist/index.js diff --git a/test/getImportMapFromNodeModules/core/issue-20/root/node_modules/lume/node_modules/lowclass/package.json b/test/getImportMapFromProjectFiles/core/issue-20/root/node_modules/lume/node_modules/lowclass/package.json similarity index 100% rename from test/getImportMapFromNodeModules/core/issue-20/root/node_modules/lume/node_modules/lowclass/package.json rename to test/getImportMapFromProjectFiles/core/issue-20/root/node_modules/lume/node_modules/lowclass/package.json diff --git a/test/getImportMapFromNodeModules/core/issue-20/root/node_modules/lume/package.json b/test/getImportMapFromProjectFiles/core/issue-20/root/node_modules/lume/package.json similarity index 100% rename from test/getImportMapFromNodeModules/core/issue-20/root/node_modules/lume/package.json rename to test/getImportMapFromProjectFiles/core/issue-20/root/node_modules/lume/package.json diff --git a/test/getImportMapFromNodeModules/core/issue-20/root/package.json b/test/getImportMapFromProjectFiles/core/issue-20/root/package.json similarity index 100% rename from test/getImportMapFromNodeModules/core/issue-20/root/package.json rename to test/getImportMapFromProjectFiles/core/issue-20/root/package.json diff --git a/test/getImportMapFromNodeModules/core/malformed-dependency-package/malformed-dependency-package.test.js b/test/getImportMapFromProjectFiles/core/malformed-dependency-package/malformed-dependency-package.test.js similarity index 74% rename from test/getImportMapFromNodeModules/core/malformed-dependency-package/malformed-dependency-package.test.js rename to test/getImportMapFromProjectFiles/core/malformed-dependency-package/malformed-dependency-package.test.js index 5143d2d8..0306ea3b 100644 --- a/test/getImportMapFromNodeModules/core/malformed-dependency-package/malformed-dependency-package.test.js +++ b/test/getImportMapFromProjectFiles/core/malformed-dependency-package/malformed-dependency-package.test.js @@ -1,10 +1,10 @@ import { assert } from "@jsenv/assert" import { resolveUrl } from "@jsenv/util" -import { getImportMapFromNodeModules } from "@jsenv/node-module-import-map" +import { getImportMapFromProjectFiles } from "@jsenv/node-module-import-map" const testDirectoryUrl = resolveUrl("./root/", import.meta.url) -const actual = await getImportMapFromNodeModules({ +const actual = await getImportMapFromProjectFiles({ logLevel: "off", projectDirectoryUrl: testDirectoryUrl, packagesSelfReference: false, diff --git a/test/getImportMapFromNodeModules/core/malformed-dependency-package/root/node_modules/malformed/package.json b/test/getImportMapFromProjectFiles/core/malformed-dependency-package/root/node_modules/malformed/package.json similarity index 100% rename from test/getImportMapFromNodeModules/core/malformed-dependency-package/root/node_modules/malformed/package.json rename to test/getImportMapFromProjectFiles/core/malformed-dependency-package/root/node_modules/malformed/package.json diff --git a/test/getImportMapFromNodeModules/core/malformed-dependency-package/root/package.json b/test/getImportMapFromProjectFiles/core/malformed-dependency-package/root/package.json similarity index 100% rename from test/getImportMapFromNodeModules/core/malformed-dependency-package/root/package.json rename to test/getImportMapFromProjectFiles/core/malformed-dependency-package/root/package.json diff --git a/test/getImportMapFromNodeModules/core/missing-dependency-package/missing-dependency-package.test.js b/test/getImportMapFromProjectFiles/core/missing-dependency-package/missing-dependency-package.test.js similarity index 71% rename from test/getImportMapFromNodeModules/core/missing-dependency-package/missing-dependency-package.test.js rename to test/getImportMapFromProjectFiles/core/missing-dependency-package/missing-dependency-package.test.js index 27f66e5e..7177d459 100644 --- a/test/getImportMapFromNodeModules/core/missing-dependency-package/missing-dependency-package.test.js +++ b/test/getImportMapFromProjectFiles/core/missing-dependency-package/missing-dependency-package.test.js @@ -1,10 +1,10 @@ import { assert } from "@jsenv/assert" import { resolveUrl } from "@jsenv/util" -import { getImportMapFromNodeModules } from "@jsenv/node-module-import-map" +import { getImportMapFromProjectFiles } from "@jsenv/node-module-import-map" const testDirectoryUrl = resolveUrl("./root/", import.meta.url) -const actual = await getImportMapFromNodeModules({ +const actual = await getImportMapFromProjectFiles({ logLevel: "error", projectDirectoryUrl: testDirectoryUrl, packagesSelfReference: false, diff --git a/test/getImportMapFromNodeModules/core/missing-dependency-package/root/package.json b/test/getImportMapFromProjectFiles/core/missing-dependency-package/root/package.json similarity index 100% rename from test/getImportMapFromNodeModules/core/missing-dependency-package/root/package.json rename to test/getImportMapFromProjectFiles/core/missing-dependency-package/root/package.json diff --git a/test/getImportMapFromNodeModules/core/missing-root-package/missing-root-package.test.js b/test/getImportMapFromProjectFiles/core/missing-root-package/missing-root-package.test.js similarity index 84% rename from test/getImportMapFromNodeModules/core/missing-root-package/missing-root-package.test.js rename to test/getImportMapFromProjectFiles/core/missing-root-package/missing-root-package.test.js index 60f37a8c..69c0336b 100644 --- a/test/getImportMapFromNodeModules/core/missing-root-package/missing-root-package.test.js +++ b/test/getImportMapFromProjectFiles/core/missing-root-package/missing-root-package.test.js @@ -1,12 +1,12 @@ import { assert } from "@jsenv/assert" import { resolveUrl, urlToFileSystemPath } from "@jsenv/util" -import { getImportMapFromNodeModules } from "@jsenv/node-module-import-map" +import { getImportMapFromProjectFiles } from "@jsenv/node-module-import-map" const testDirectoryUrl = resolveUrl("./root/", import.meta.url) const packageFileUrl = resolveUrl("./package.json", testDirectoryUrl) try { - await getImportMapFromNodeModules({ + await getImportMapFromProjectFiles({ projectDirectoryUrl: testDirectoryUrl, packagesSelfReference: false, }) diff --git a/test/getImportMapFromNodeModules/core/optional-dependency/optional-dependency.test.js b/test/getImportMapFromProjectFiles/core/optional-dependency/optional-dependency.test.js similarity index 70% rename from test/getImportMapFromNodeModules/core/optional-dependency/optional-dependency.test.js rename to test/getImportMapFromProjectFiles/core/optional-dependency/optional-dependency.test.js index f5f46cc6..78599d97 100644 --- a/test/getImportMapFromNodeModules/core/optional-dependency/optional-dependency.test.js +++ b/test/getImportMapFromProjectFiles/core/optional-dependency/optional-dependency.test.js @@ -1,10 +1,10 @@ import { assert } from "@jsenv/assert" import { resolveUrl } from "@jsenv/util" -import { getImportMapFromNodeModules } from "@jsenv/node-module-import-map" +import { getImportMapFromProjectFiles } from "@jsenv/node-module-import-map" const testDirectoryUrl = resolveUrl("./root/", import.meta.url) -const actual = await getImportMapFromNodeModules({ +const actual = await getImportMapFromProjectFiles({ projectDirectoryUrl: testDirectoryUrl, packagesSelfReference: false, }) diff --git a/test/getImportMapFromNodeModules/core/optional-dependency/root/package.json b/test/getImportMapFromProjectFiles/core/optional-dependency/root/package.json similarity index 100% rename from test/getImportMapFromNodeModules/core/optional-dependency/root/package.json rename to test/getImportMapFromProjectFiles/core/optional-dependency/root/package.json diff --git a/test/getImportMapFromNodeModules/core/scoped-inside-scoped/root/node_modules/@jsenv/bundling/node_modules/@jsenv/core/node_modules/@dmail/project-structure/package.json b/test/getImportMapFromProjectFiles/core/scoped-inside-scoped/root/node_modules/@jsenv/bundling/node_modules/@jsenv/core/node_modules/@dmail/project-structure/package.json similarity index 100% rename from test/getImportMapFromNodeModules/core/scoped-inside-scoped/root/node_modules/@jsenv/bundling/node_modules/@jsenv/core/node_modules/@dmail/project-structure/package.json rename to test/getImportMapFromProjectFiles/core/scoped-inside-scoped/root/node_modules/@jsenv/bundling/node_modules/@jsenv/core/node_modules/@dmail/project-structure/package.json diff --git a/test/getImportMapFromNodeModules/core/scoped-inside-scoped/root/node_modules/@jsenv/bundling/node_modules/@jsenv/core/node_modules/@dmail/project-structure/whatever.js b/test/getImportMapFromProjectFiles/core/scoped-inside-scoped/root/node_modules/@jsenv/bundling/node_modules/@jsenv/core/node_modules/@dmail/project-structure/whatever.js similarity index 100% rename from test/getImportMapFromNodeModules/core/scoped-inside-scoped/root/node_modules/@jsenv/bundling/node_modules/@jsenv/core/node_modules/@dmail/project-structure/whatever.js rename to test/getImportMapFromProjectFiles/core/scoped-inside-scoped/root/node_modules/@jsenv/bundling/node_modules/@jsenv/core/node_modules/@dmail/project-structure/whatever.js diff --git a/test/getImportMapFromNodeModules/core/scoped-inside-scoped/root/node_modules/@jsenv/bundling/node_modules/@jsenv/core/package.json b/test/getImportMapFromProjectFiles/core/scoped-inside-scoped/root/node_modules/@jsenv/bundling/node_modules/@jsenv/core/package.json similarity index 100% rename from test/getImportMapFromNodeModules/core/scoped-inside-scoped/root/node_modules/@jsenv/bundling/node_modules/@jsenv/core/package.json rename to test/getImportMapFromProjectFiles/core/scoped-inside-scoped/root/node_modules/@jsenv/bundling/node_modules/@jsenv/core/package.json diff --git a/test/getImportMapFromNodeModules/core/scoped-inside-scoped/root/node_modules/@jsenv/bundling/node_modules/@jsenv/core/whatever.js b/test/getImportMapFromProjectFiles/core/scoped-inside-scoped/root/node_modules/@jsenv/bundling/node_modules/@jsenv/core/whatever.js similarity index 100% rename from test/getImportMapFromNodeModules/core/scoped-inside-scoped/root/node_modules/@jsenv/bundling/node_modules/@jsenv/core/whatever.js rename to test/getImportMapFromProjectFiles/core/scoped-inside-scoped/root/node_modules/@jsenv/bundling/node_modules/@jsenv/core/whatever.js diff --git a/test/getImportMapFromNodeModules/core/scoped-inside-scoped/root/node_modules/@jsenv/bundling/package.json b/test/getImportMapFromProjectFiles/core/scoped-inside-scoped/root/node_modules/@jsenv/bundling/package.json similarity index 100% rename from test/getImportMapFromNodeModules/core/scoped-inside-scoped/root/node_modules/@jsenv/bundling/package.json rename to test/getImportMapFromProjectFiles/core/scoped-inside-scoped/root/node_modules/@jsenv/bundling/package.json diff --git a/test/getImportMapFromNodeModules/core/scoped-inside-scoped/root/node_modules/@jsenv/bundling/whatever.js b/test/getImportMapFromProjectFiles/core/scoped-inside-scoped/root/node_modules/@jsenv/bundling/whatever.js similarity index 100% rename from test/getImportMapFromNodeModules/core/scoped-inside-scoped/root/node_modules/@jsenv/bundling/whatever.js rename to test/getImportMapFromProjectFiles/core/scoped-inside-scoped/root/node_modules/@jsenv/bundling/whatever.js diff --git a/test/getImportMapFromNodeModules/core/scoped-inside-scoped/root/package.json b/test/getImportMapFromProjectFiles/core/scoped-inside-scoped/root/package.json similarity index 100% rename from test/getImportMapFromNodeModules/core/scoped-inside-scoped/root/package.json rename to test/getImportMapFromProjectFiles/core/scoped-inside-scoped/root/package.json diff --git a/test/getImportMapFromNodeModules/core/scoped-inside-scoped/scoped-inside-scoped.test.js b/test/getImportMapFromProjectFiles/core/scoped-inside-scoped/scoped-inside-scoped.test.js similarity index 85% rename from test/getImportMapFromNodeModules/core/scoped-inside-scoped/scoped-inside-scoped.test.js rename to test/getImportMapFromProjectFiles/core/scoped-inside-scoped/scoped-inside-scoped.test.js index 804f8cfa..b5818287 100644 --- a/test/getImportMapFromNodeModules/core/scoped-inside-scoped/scoped-inside-scoped.test.js +++ b/test/getImportMapFromProjectFiles/core/scoped-inside-scoped/scoped-inside-scoped.test.js @@ -1,10 +1,10 @@ import { assert } from "@jsenv/assert" import { resolveUrl } from "@jsenv/util" -import { getImportMapFromNodeModules } from "@jsenv/node-module-import-map" +import { getImportMapFromProjectFiles } from "@jsenv/node-module-import-map" const testDirectoryUrl = resolveUrl("./root/", import.meta.url) -const actual = await getImportMapFromNodeModules({ +const actual = await getImportMapFromProjectFiles({ projectDirectoryUrl: testDirectoryUrl, projectPackageDevDependenciesIncluded: true, packagesSelfReference: false, diff --git a/test/getImportMapFromNodeModules/core/shared-indirect/root/node_modules/bar/bar.js b/test/getImportMapFromProjectFiles/core/shared-indirect/root/node_modules/bar/bar.js similarity index 100% rename from test/getImportMapFromNodeModules/core/shared-indirect/root/node_modules/bar/bar.js rename to test/getImportMapFromProjectFiles/core/shared-indirect/root/node_modules/bar/bar.js diff --git a/test/getImportMapFromNodeModules/core/shared-indirect/root/node_modules/bar/package.json b/test/getImportMapFromProjectFiles/core/shared-indirect/root/node_modules/bar/package.json similarity index 100% rename from test/getImportMapFromNodeModules/core/shared-indirect/root/node_modules/bar/package.json rename to test/getImportMapFromProjectFiles/core/shared-indirect/root/node_modules/bar/package.json diff --git a/test/getImportMapFromNodeModules/core/shared-indirect/root/node_modules/foo/foo.js b/test/getImportMapFromProjectFiles/core/shared-indirect/root/node_modules/foo/foo.js similarity index 100% rename from test/getImportMapFromNodeModules/core/shared-indirect/root/node_modules/foo/foo.js rename to test/getImportMapFromProjectFiles/core/shared-indirect/root/node_modules/foo/foo.js diff --git a/test/getImportMapFromNodeModules/core/shared-indirect/root/node_modules/foo/package.json b/test/getImportMapFromProjectFiles/core/shared-indirect/root/node_modules/foo/package.json similarity index 100% rename from test/getImportMapFromNodeModules/core/shared-indirect/root/node_modules/foo/package.json rename to test/getImportMapFromProjectFiles/core/shared-indirect/root/node_modules/foo/package.json diff --git a/test/getImportMapFromNodeModules/core/shared-indirect/root/package.json b/test/getImportMapFromProjectFiles/core/shared-indirect/root/package.json similarity index 100% rename from test/getImportMapFromNodeModules/core/shared-indirect/root/package.json rename to test/getImportMapFromProjectFiles/core/shared-indirect/root/package.json diff --git a/test/getImportMapFromNodeModules/core/shared-indirect/shared-indirect.test.js b/test/getImportMapFromProjectFiles/core/shared-indirect/shared-indirect.test.js similarity index 89% rename from test/getImportMapFromNodeModules/core/shared-indirect/shared-indirect.test.js rename to test/getImportMapFromProjectFiles/core/shared-indirect/shared-indirect.test.js index 5a8d31c3..1c01c584 100644 --- a/test/getImportMapFromNodeModules/core/shared-indirect/shared-indirect.test.js +++ b/test/getImportMapFromProjectFiles/core/shared-indirect/shared-indirect.test.js @@ -1,11 +1,11 @@ import { normalizeImportMap, resolveImport } from "@jsenv/import-map" import { resolveUrl } from "@jsenv/util" import { assert } from "@jsenv/assert" -import { getImportMapFromNodeModules } from "@jsenv/node-module-import-map" +import { getImportMapFromProjectFiles } from "@jsenv/node-module-import-map" const testDirectoryUrl = resolveUrl("./root/", import.meta.url) -const importMap = await getImportMapFromNodeModules({ +const importMap = await getImportMapFromProjectFiles({ projectDirectoryUrl: testDirectoryUrl, }) { diff --git a/test/getImportMapFromNodeModules/core/shared/root/node_modules/bar/bar.js b/test/getImportMapFromProjectFiles/core/shared/root/node_modules/bar/bar.js similarity index 100% rename from test/getImportMapFromNodeModules/core/shared/root/node_modules/bar/bar.js rename to test/getImportMapFromProjectFiles/core/shared/root/node_modules/bar/bar.js diff --git a/test/getImportMapFromNodeModules/core/shared/root/node_modules/bar/package.json b/test/getImportMapFromProjectFiles/core/shared/root/node_modules/bar/package.json similarity index 100% rename from test/getImportMapFromNodeModules/core/shared/root/node_modules/bar/package.json rename to test/getImportMapFromProjectFiles/core/shared/root/node_modules/bar/package.json diff --git a/test/getImportMapFromNodeModules/core/shared/root/node_modules/foo/foo.js b/test/getImportMapFromProjectFiles/core/shared/root/node_modules/foo/foo.js similarity index 100% rename from test/getImportMapFromNodeModules/core/shared/root/node_modules/foo/foo.js rename to test/getImportMapFromProjectFiles/core/shared/root/node_modules/foo/foo.js diff --git a/test/getImportMapFromNodeModules/core/shared/root/node_modules/foo/package.json b/test/getImportMapFromProjectFiles/core/shared/root/node_modules/foo/package.json similarity index 100% rename from test/getImportMapFromNodeModules/core/shared/root/node_modules/foo/package.json rename to test/getImportMapFromProjectFiles/core/shared/root/node_modules/foo/package.json diff --git a/test/getImportMapFromNodeModules/core/shared/root/package.json b/test/getImportMapFromProjectFiles/core/shared/root/package.json similarity index 100% rename from test/getImportMapFromNodeModules/core/shared/root/package.json rename to test/getImportMapFromProjectFiles/core/shared/root/package.json diff --git a/test/getImportMapFromNodeModules/core/shared/shared.test.js b/test/getImportMapFromProjectFiles/core/shared/shared.test.js similarity index 94% rename from test/getImportMapFromNodeModules/core/shared/shared.test.js rename to test/getImportMapFromProjectFiles/core/shared/shared.test.js index decde6c9..6385b336 100644 --- a/test/getImportMapFromNodeModules/core/shared/shared.test.js +++ b/test/getImportMapFromProjectFiles/core/shared/shared.test.js @@ -1,11 +1,11 @@ import { normalizeImportMap, resolveImport } from "@jsenv/import-map" import { resolveUrl } from "@jsenv/util" import { assert } from "@jsenv/assert" -import { getImportMapFromNodeModules } from "@jsenv/node-module-import-map" +import { getImportMapFromProjectFiles } from "@jsenv/node-module-import-map" const testDirectoryUrl = resolveUrl("./root/", import.meta.url) -const importMap = await getImportMapFromNodeModules({ +const importMap = await getImportMapFromProjectFiles({ projectDirectoryUrl: testDirectoryUrl, }) { diff --git a/test/getImportMapFromNodeModules/core/sibling-and-deep/root/index.js b/test/getImportMapFromProjectFiles/core/sibling-and-deep/root/index.js similarity index 100% rename from test/getImportMapFromNodeModules/core/sibling-and-deep/root/index.js rename to test/getImportMapFromProjectFiles/core/sibling-and-deep/root/index.js diff --git a/test/getImportMapFromNodeModules/core/sibling-and-deep/root/node_modules/nested/node_modules/bar/bar.js b/test/getImportMapFromProjectFiles/core/sibling-and-deep/root/node_modules/nested/node_modules/bar/bar.js similarity index 100% rename from test/getImportMapFromNodeModules/core/sibling-and-deep/root/node_modules/nested/node_modules/bar/bar.js rename to test/getImportMapFromProjectFiles/core/sibling-and-deep/root/node_modules/nested/node_modules/bar/bar.js diff --git a/test/getImportMapFromNodeModules/core/sibling-and-deep/root/node_modules/nested/node_modules/bar/package.json b/test/getImportMapFromProjectFiles/core/sibling-and-deep/root/node_modules/nested/node_modules/bar/package.json similarity index 100% rename from test/getImportMapFromNodeModules/core/sibling-and-deep/root/node_modules/nested/node_modules/bar/package.json rename to test/getImportMapFromProjectFiles/core/sibling-and-deep/root/node_modules/nested/node_modules/bar/package.json diff --git a/test/getImportMapFromNodeModules/core/sibling-and-deep/root/node_modules/nested/node_modules/foo/foo.js b/test/getImportMapFromProjectFiles/core/sibling-and-deep/root/node_modules/nested/node_modules/foo/foo.js similarity index 100% rename from test/getImportMapFromNodeModules/core/sibling-and-deep/root/node_modules/nested/node_modules/foo/foo.js rename to test/getImportMapFromProjectFiles/core/sibling-and-deep/root/node_modules/nested/node_modules/foo/foo.js diff --git a/test/getImportMapFromNodeModules/core/sibling-and-deep/root/node_modules/nested/node_modules/foo/package.json b/test/getImportMapFromProjectFiles/core/sibling-and-deep/root/node_modules/nested/node_modules/foo/package.json similarity index 100% rename from test/getImportMapFromNodeModules/core/sibling-and-deep/root/node_modules/nested/node_modules/foo/package.json rename to test/getImportMapFromProjectFiles/core/sibling-and-deep/root/node_modules/nested/node_modules/foo/package.json diff --git a/test/getImportMapFromNodeModules/core/sibling-and-deep/root/node_modules/nested/package.json b/test/getImportMapFromProjectFiles/core/sibling-and-deep/root/node_modules/nested/package.json similarity index 100% rename from test/getImportMapFromNodeModules/core/sibling-and-deep/root/node_modules/nested/package.json rename to test/getImportMapFromProjectFiles/core/sibling-and-deep/root/node_modules/nested/package.json diff --git a/test/getImportMapFromNodeModules/core/sibling-and-deep/root/package.json b/test/getImportMapFromProjectFiles/core/sibling-and-deep/root/package.json similarity index 100% rename from test/getImportMapFromNodeModules/core/sibling-and-deep/root/package.json rename to test/getImportMapFromProjectFiles/core/sibling-and-deep/root/package.json diff --git a/test/getImportMapFromNodeModules/core/sibling-and-deep/sibling-and-deep.test.js b/test/getImportMapFromProjectFiles/core/sibling-and-deep/sibling-and-deep.test.js similarity index 86% rename from test/getImportMapFromNodeModules/core/sibling-and-deep/sibling-and-deep.test.js rename to test/getImportMapFromProjectFiles/core/sibling-and-deep/sibling-and-deep.test.js index 0068e911..ba8406a0 100644 --- a/test/getImportMapFromNodeModules/core/sibling-and-deep/sibling-and-deep.test.js +++ b/test/getImportMapFromProjectFiles/core/sibling-and-deep/sibling-and-deep.test.js @@ -1,10 +1,10 @@ import { assert } from "@jsenv/assert" import { resolveUrl } from "@jsenv/util" -import { getImportMapFromNodeModules } from "@jsenv/node-module-import-map" +import { getImportMapFromProjectFiles } from "@jsenv/node-module-import-map" const testDirectoryUrl = resolveUrl("./root/", import.meta.url) -const actual = await getImportMapFromNodeModules({ +const actual = await getImportMapFromProjectFiles({ projectDirectoryUrl: testDirectoryUrl, }) const expected = { diff --git a/test/getImportMapFromNodeModules/core/symlink/root/index.js b/test/getImportMapFromProjectFiles/core/symlink/root/index.js similarity index 100% rename from test/getImportMapFromNodeModules/core/symlink/root/index.js rename to test/getImportMapFromProjectFiles/core/symlink/root/index.js diff --git a/test/getImportMapFromNodeModules/core/symlink/root/node_modules/foo/index.js b/test/getImportMapFromProjectFiles/core/symlink/root/node_modules/foo/index.js similarity index 100% rename from test/getImportMapFromNodeModules/core/symlink/root/node_modules/foo/index.js rename to test/getImportMapFromProjectFiles/core/symlink/root/node_modules/foo/index.js diff --git a/test/getImportMapFromNodeModules/core/symlink/root/node_modules/foo/package.json b/test/getImportMapFromProjectFiles/core/symlink/root/node_modules/foo/package.json similarity index 100% rename from test/getImportMapFromNodeModules/core/symlink/root/node_modules/foo/package.json rename to test/getImportMapFromProjectFiles/core/symlink/root/node_modules/foo/package.json diff --git a/test/getImportMapFromNodeModules/core/symlink/root/package.json b/test/getImportMapFromProjectFiles/core/symlink/root/package.json similarity index 100% rename from test/getImportMapFromNodeModules/core/symlink/root/package.json rename to test/getImportMapFromProjectFiles/core/symlink/root/package.json diff --git a/test/getImportMapFromNodeModules/core/symlink/root/project/index.js b/test/getImportMapFromProjectFiles/core/symlink/root/project/index.js similarity index 100% rename from test/getImportMapFromNodeModules/core/symlink/root/project/index.js rename to test/getImportMapFromProjectFiles/core/symlink/root/project/index.js diff --git a/test/getImportMapFromNodeModules/core/symlink/root/project/node_modules/foo/index.js b/test/getImportMapFromProjectFiles/core/symlink/root/project/node_modules/foo/index.js similarity index 100% rename from test/getImportMapFromNodeModules/core/symlink/root/project/node_modules/foo/index.js rename to test/getImportMapFromProjectFiles/core/symlink/root/project/node_modules/foo/index.js diff --git a/test/getImportMapFromNodeModules/core/symlink/root/project/node_modules/foo/package.json b/test/getImportMapFromProjectFiles/core/symlink/root/project/node_modules/foo/package.json similarity index 100% rename from test/getImportMapFromNodeModules/core/symlink/root/project/node_modules/foo/package.json rename to test/getImportMapFromProjectFiles/core/symlink/root/project/node_modules/foo/package.json diff --git a/test/getImportMapFromNodeModules/core/symlink/root/project/package.json b/test/getImportMapFromProjectFiles/core/symlink/root/project/package.json similarity index 100% rename from test/getImportMapFromNodeModules/core/symlink/root/project/package.json rename to test/getImportMapFromProjectFiles/core/symlink/root/project/package.json diff --git a/test/getImportMapFromNodeModules/core/symlink/symlink.test.js b/test/getImportMapFromProjectFiles/core/symlink/symlink.test.js similarity index 80% rename from test/getImportMapFromNodeModules/core/symlink/symlink.test.js rename to test/getImportMapFromProjectFiles/core/symlink/symlink.test.js index c4c057bb..cb4b1403 100644 --- a/test/getImportMapFromNodeModules/core/symlink/symlink.test.js +++ b/test/getImportMapFromProjectFiles/core/symlink/symlink.test.js @@ -1,10 +1,10 @@ import { assert } from "@jsenv/assert" import { resolveUrl } from "@jsenv/util" -import { getImportMapFromNodeModules } from "@jsenv/node-module-import-map" +import { getImportMapFromProjectFiles } from "@jsenv/node-module-import-map" const testDirectoryUrl = resolveUrl("./root/", import.meta.url) -const actual = await getImportMapFromNodeModules({ +const actual = await getImportMapFromProjectFiles({ projectDirectoryUrl: testDirectoryUrl, }) const expected = { diff --git a/test/getImportMapFromNodeModules/included-predicate/included-predicate.test.js b/test/getImportMapFromProjectFiles/included-predicate/included-predicate.test.js similarity index 76% rename from test/getImportMapFromNodeModules/included-predicate/included-predicate.test.js rename to test/getImportMapFromProjectFiles/included-predicate/included-predicate.test.js index 245f394b..aa1955a6 100644 --- a/test/getImportMapFromNodeModules/included-predicate/included-predicate.test.js +++ b/test/getImportMapFromProjectFiles/included-predicate/included-predicate.test.js @@ -1,10 +1,10 @@ import { assert } from "@jsenv/assert" import { resolveUrl } from "@jsenv/util" -import { getImportMapFromNodeModules } from "@jsenv/node-module-import-map" +import { getImportMapFromProjectFiles } from "@jsenv/node-module-import-map" const testDirectoryUrl = resolveUrl("./root/", import.meta.url) -const actual = await getImportMapFromNodeModules({ +const actual = await getImportMapFromProjectFiles({ projectDirectoryUrl: testDirectoryUrl, packagesSelfReference: false, packageIncludedPredicate: ({ packageName }) => packageName !== "foo", diff --git a/test/getImportMapFromNodeModules/included-predicate/root/node_modules/bar/package.json b/test/getImportMapFromProjectFiles/included-predicate/root/node_modules/bar/package.json similarity index 100% rename from test/getImportMapFromNodeModules/included-predicate/root/node_modules/bar/package.json rename to test/getImportMapFromProjectFiles/included-predicate/root/node_modules/bar/package.json diff --git a/test/getImportMapFromNodeModules/included-predicate/root/node_modules/foo/foo.js b/test/getImportMapFromProjectFiles/included-predicate/root/node_modules/foo/foo.js similarity index 100% rename from test/getImportMapFromNodeModules/included-predicate/root/node_modules/foo/foo.js rename to test/getImportMapFromProjectFiles/included-predicate/root/node_modules/foo/foo.js diff --git a/test/getImportMapFromNodeModules/included-predicate/root/node_modules/foo/package.json b/test/getImportMapFromProjectFiles/included-predicate/root/node_modules/foo/package.json similarity index 100% rename from test/getImportMapFromNodeModules/included-predicate/root/node_modules/foo/package.json rename to test/getImportMapFromProjectFiles/included-predicate/root/node_modules/foo/package.json diff --git a/test/getImportMapFromNodeModules/included-predicate/root/package.json b/test/getImportMapFromProjectFiles/included-predicate/root/package.json similarity index 100% rename from test/getImportMapFromNodeModules/included-predicate/root/package.json rename to test/getImportMapFromProjectFiles/included-predicate/root/package.json diff --git a/test/getImportMapFromNodeModules/manual-override/manual-override.test.js b/test/getImportMapFromProjectFiles/manual-override/manual-override.test.js similarity index 79% rename from test/getImportMapFromNodeModules/manual-override/manual-override.test.js rename to test/getImportMapFromProjectFiles/manual-override/manual-override.test.js index e21ecadf..3dc98d67 100644 --- a/test/getImportMapFromNodeModules/manual-override/manual-override.test.js +++ b/test/getImportMapFromProjectFiles/manual-override/manual-override.test.js @@ -1,10 +1,10 @@ import { assert } from "@jsenv/assert" import { resolveUrl } from "@jsenv/util" -import { getImportMapFromNodeModules } from "@jsenv/node-module-import-map" +import { getImportMapFromProjectFiles } from "@jsenv/node-module-import-map" const testDirectoryUrl = resolveUrl("./", import.meta.url) -const actual = await getImportMapFromNodeModules({ +const actual = await getImportMapFromProjectFiles({ projectDirectoryUrl: testDirectoryUrl, packagesManualOverrides: { bar: { diff --git a/test/getImportMapFromNodeModules/manual-override/node_modules/bar/bar.js b/test/getImportMapFromProjectFiles/manual-override/node_modules/bar/bar.js similarity index 100% rename from test/getImportMapFromNodeModules/manual-override/node_modules/bar/bar.js rename to test/getImportMapFromProjectFiles/manual-override/node_modules/bar/bar.js diff --git a/test/getImportMapFromNodeModules/manual-override/node_modules/bar/package.json b/test/getImportMapFromProjectFiles/manual-override/node_modules/bar/package.json similarity index 100% rename from test/getImportMapFromNodeModules/manual-override/node_modules/bar/package.json rename to test/getImportMapFromProjectFiles/manual-override/node_modules/bar/package.json diff --git a/test/getImportMapFromNodeModules/manual-override/package.json b/test/getImportMapFromProjectFiles/manual-override/package.json similarity index 100% rename from test/getImportMapFromNodeModules/manual-override/package.json rename to test/getImportMapFromProjectFiles/manual-override/package.json diff --git a/test/getImportMapFromNodeModules/package-exports-field/exports-and-main/exports-and-main.test.js b/test/getImportMapFromProjectFiles/package-exports-field/exports-and-main/exports-and-main.test.js similarity index 72% rename from test/getImportMapFromNodeModules/package-exports-field/exports-and-main/exports-and-main.test.js rename to test/getImportMapFromProjectFiles/package-exports-field/exports-and-main/exports-and-main.test.js index 22f42bda..44269ecf 100644 --- a/test/getImportMapFromNodeModules/package-exports-field/exports-and-main/exports-and-main.test.js +++ b/test/getImportMapFromProjectFiles/package-exports-field/exports-and-main/exports-and-main.test.js @@ -1,10 +1,10 @@ import { assert } from "@jsenv/assert" import { resolveUrl } from "@jsenv/util" -import { getImportMapFromNodeModules } from "@jsenv/node-module-import-map" +import { getImportMapFromProjectFiles } from "@jsenv/node-module-import-map" const testDirectoryUrl = resolveUrl("./root/", import.meta.url) -const actual = await getImportMapFromNodeModules({ +const actual = await getImportMapFromProjectFiles({ projectDirectoryUrl: testDirectoryUrl, packagesSelfReference: false, }) diff --git a/test/getImportMapFromNodeModules/package-exports-field/exports-and-main/root/node_modules/foo/file.cjs b/test/getImportMapFromProjectFiles/package-exports-field/exports-and-main/root/node_modules/foo/file.cjs similarity index 100% rename from test/getImportMapFromNodeModules/package-exports-field/exports-and-main/root/node_modules/foo/file.cjs rename to test/getImportMapFromProjectFiles/package-exports-field/exports-and-main/root/node_modules/foo/file.cjs diff --git a/test/getImportMapFromNodeModules/package-exports-field/exports-and-main/root/node_modules/foo/index.js b/test/getImportMapFromProjectFiles/package-exports-field/exports-and-main/root/node_modules/foo/index.js similarity index 100% rename from test/getImportMapFromNodeModules/package-exports-field/exports-and-main/root/node_modules/foo/index.js rename to test/getImportMapFromProjectFiles/package-exports-field/exports-and-main/root/node_modules/foo/index.js diff --git a/test/getImportMapFromNodeModules/package-exports-field/exports-and-main/root/node_modules/foo/package.json b/test/getImportMapFromProjectFiles/package-exports-field/exports-and-main/root/node_modules/foo/package.json similarity index 100% rename from test/getImportMapFromNodeModules/package-exports-field/exports-and-main/root/node_modules/foo/package.json rename to test/getImportMapFromProjectFiles/package-exports-field/exports-and-main/root/node_modules/foo/package.json diff --git a/test/getImportMapFromNodeModules/package-exports-field/exports-and-main/root/package.json b/test/getImportMapFromProjectFiles/package-exports-field/exports-and-main/root/package.json similarity index 100% rename from test/getImportMapFromNodeModules/package-exports-field/exports-and-main/root/package.json rename to test/getImportMapFromProjectFiles/package-exports-field/exports-and-main/root/package.json diff --git a/test/getImportMapFromNodeModules/package-exports-field/exports-complex/exports-complex.test.js b/test/getImportMapFromProjectFiles/package-exports-field/exports-complex/exports-complex.test.js similarity index 92% rename from test/getImportMapFromNodeModules/package-exports-field/exports-complex/exports-complex.test.js rename to test/getImportMapFromProjectFiles/package-exports-field/exports-complex/exports-complex.test.js index 693862e9..3c9ff291 100644 --- a/test/getImportMapFromNodeModules/package-exports-field/exports-complex/exports-complex.test.js +++ b/test/getImportMapFromProjectFiles/package-exports-field/exports-complex/exports-complex.test.js @@ -1,11 +1,11 @@ import { assert } from "@jsenv/assert" import { resolveUrl } from "@jsenv/util" -import { getImportMapFromNodeModules } from "@jsenv/node-module-import-map" +import { getImportMapFromProjectFiles } from "@jsenv/node-module-import-map" const testDirectoryUrl = resolveUrl("./", import.meta.url) const getImportMap = async ({ packagesExportsPreference } = {}) => { - return getImportMapFromNodeModules({ + return getImportMapFromProjectFiles({ projectDirectoryUrl: testDirectoryUrl, packagesSelfReference: false, packagesExportsPreference, diff --git a/test/getImportMapFromNodeModules/package-exports-field/exports-complex/node_modules/foo/file.cjs b/test/getImportMapFromProjectFiles/package-exports-field/exports-complex/node_modules/foo/file.cjs similarity index 100% rename from test/getImportMapFromNodeModules/package-exports-field/exports-complex/node_modules/foo/file.cjs rename to test/getImportMapFromProjectFiles/package-exports-field/exports-complex/node_modules/foo/file.cjs diff --git a/test/getImportMapFromNodeModules/package-exports-field/exports-complex/node_modules/foo/package.json b/test/getImportMapFromProjectFiles/package-exports-field/exports-complex/node_modules/foo/package.json similarity index 100% rename from test/getImportMapFromNodeModules/package-exports-field/exports-complex/node_modules/foo/package.json rename to test/getImportMapFromProjectFiles/package-exports-field/exports-complex/node_modules/foo/package.json diff --git a/test/getImportMapFromNodeModules/package-exports-field/exports-complex/package.json b/test/getImportMapFromProjectFiles/package-exports-field/exports-complex/package.json similarity index 100% rename from test/getImportMapFromNodeModules/package-exports-field/exports-complex/package.json rename to test/getImportMapFromProjectFiles/package-exports-field/exports-complex/package.json diff --git a/test/getImportMapFromNodeModules/package-exports-field/exports-condition-nested/exports-condition-nested.test.js b/test/getImportMapFromProjectFiles/package-exports-field/exports-condition-nested/exports-condition-nested.test.js similarity index 78% rename from test/getImportMapFromNodeModules/package-exports-field/exports-condition-nested/exports-condition-nested.test.js rename to test/getImportMapFromProjectFiles/package-exports-field/exports-condition-nested/exports-condition-nested.test.js index 06e897ab..98592d66 100644 --- a/test/getImportMapFromNodeModules/package-exports-field/exports-condition-nested/exports-condition-nested.test.js +++ b/test/getImportMapFromProjectFiles/package-exports-field/exports-condition-nested/exports-condition-nested.test.js @@ -1,11 +1,11 @@ import { assert } from "@jsenv/assert" import { resolveUrl } from "@jsenv/util" -import { getImportMapFromNodeModules } from "@jsenv/node-module-import-map" +import { getImportMapFromProjectFiles } from "@jsenv/node-module-import-map" const testDirectoryUrl = resolveUrl("./root/", import.meta.url) { - const importMap = await getImportMapFromNodeModules({ + const importMap = await getImportMapFromProjectFiles({ projectDirectoryUrl: testDirectoryUrl, target: "node", packagesSelfReference: false, @@ -21,7 +21,7 @@ const testDirectoryUrl = resolveUrl("./root/", import.meta.url) } { - const importMap = await getImportMapFromNodeModules({ + const importMap = await getImportMapFromProjectFiles({ projectDirectoryUrl: testDirectoryUrl, target: "browser", packagesSelfReference: false, diff --git a/test/getImportMapFromNodeModules/package-exports-field/exports-condition-nested/root/node_modules/foo/package.json b/test/getImportMapFromProjectFiles/package-exports-field/exports-condition-nested/root/node_modules/foo/package.json similarity index 100% rename from test/getImportMapFromNodeModules/package-exports-field/exports-condition-nested/root/node_modules/foo/package.json rename to test/getImportMapFromProjectFiles/package-exports-field/exports-condition-nested/root/node_modules/foo/package.json diff --git a/test/getImportMapFromNodeModules/package-exports-field/exports-condition-nested/root/package.json b/test/getImportMapFromProjectFiles/package-exports-field/exports-condition-nested/root/package.json similarity index 100% rename from test/getImportMapFromNodeModules/package-exports-field/exports-condition-nested/root/package.json rename to test/getImportMapFromProjectFiles/package-exports-field/exports-condition-nested/root/package.json diff --git a/test/getImportMapFromNodeModules/package-exports-field/exports-directory-scoped/exports-directory-scoped.test.js b/test/getImportMapFromProjectFiles/package-exports-field/exports-directory-scoped/exports-directory-scoped.test.js similarity index 85% rename from test/getImportMapFromNodeModules/package-exports-field/exports-directory-scoped/exports-directory-scoped.test.js rename to test/getImportMapFromProjectFiles/package-exports-field/exports-directory-scoped/exports-directory-scoped.test.js index 9e38ae91..a3cd2efa 100644 --- a/test/getImportMapFromNodeModules/package-exports-field/exports-directory-scoped/exports-directory-scoped.test.js +++ b/test/getImportMapFromProjectFiles/package-exports-field/exports-directory-scoped/exports-directory-scoped.test.js @@ -1,10 +1,10 @@ import { assert } from "@jsenv/assert" import { resolveUrl } from "@jsenv/util" -import { getImportMapFromNodeModules } from "@jsenv/node-module-import-map" +import { getImportMapFromProjectFiles } from "@jsenv/node-module-import-map" const testDirectoryUrl = resolveUrl("./root/", import.meta.url) -const actual = await getImportMapFromNodeModules({ +const actual = await getImportMapFromProjectFiles({ projectDirectoryUrl: testDirectoryUrl, packagesSelfReference: false, }) diff --git a/test/getImportMapFromNodeModules/package-exports-field/exports-directory-scoped/root/node_modules/foo/index.js b/test/getImportMapFromProjectFiles/package-exports-field/exports-directory-scoped/root/node_modules/foo/index.js similarity index 100% rename from test/getImportMapFromNodeModules/package-exports-field/exports-directory-scoped/root/node_modules/foo/index.js rename to test/getImportMapFromProjectFiles/package-exports-field/exports-directory-scoped/root/node_modules/foo/index.js diff --git a/test/getImportMapFromNodeModules/package-exports-field/exports-directory-scoped/root/node_modules/foo/node_modules/exporting-folder/index.js b/test/getImportMapFromProjectFiles/package-exports-field/exports-directory-scoped/root/node_modules/foo/node_modules/exporting-folder/index.js similarity index 100% rename from test/getImportMapFromNodeModules/package-exports-field/exports-directory-scoped/root/node_modules/foo/node_modules/exporting-folder/index.js rename to test/getImportMapFromProjectFiles/package-exports-field/exports-directory-scoped/root/node_modules/foo/node_modules/exporting-folder/index.js diff --git a/test/getImportMapFromNodeModules/package-exports-field/exports-directory-scoped/root/node_modules/foo/node_modules/exporting-folder/package.json b/test/getImportMapFromProjectFiles/package-exports-field/exports-directory-scoped/root/node_modules/foo/node_modules/exporting-folder/package.json similarity index 100% rename from test/getImportMapFromNodeModules/package-exports-field/exports-directory-scoped/root/node_modules/foo/node_modules/exporting-folder/package.json rename to test/getImportMapFromProjectFiles/package-exports-field/exports-directory-scoped/root/node_modules/foo/node_modules/exporting-folder/package.json diff --git a/test/getImportMapFromNodeModules/package-exports-field/exports-directory-scoped/root/node_modules/foo/package.json b/test/getImportMapFromProjectFiles/package-exports-field/exports-directory-scoped/root/node_modules/foo/package.json similarity index 100% rename from test/getImportMapFromNodeModules/package-exports-field/exports-directory-scoped/root/node_modules/foo/package.json rename to test/getImportMapFromProjectFiles/package-exports-field/exports-directory-scoped/root/node_modules/foo/package.json diff --git a/test/getImportMapFromNodeModules/package-exports-field/exports-directory-scoped/root/package.json b/test/getImportMapFromProjectFiles/package-exports-field/exports-directory-scoped/root/package.json similarity index 100% rename from test/getImportMapFromNodeModules/package-exports-field/exports-directory-scoped/root/package.json rename to test/getImportMapFromProjectFiles/package-exports-field/exports-directory-scoped/root/package.json diff --git a/test/getImportMapFromNodeModules/package-exports-field/exports-directory/exports-directory.test.js b/test/getImportMapFromProjectFiles/package-exports-field/exports-directory/exports-directory.test.js similarity index 76% rename from test/getImportMapFromNodeModules/package-exports-field/exports-directory/exports-directory.test.js rename to test/getImportMapFromProjectFiles/package-exports-field/exports-directory/exports-directory.test.js index 1562b0dd..c4be3229 100644 --- a/test/getImportMapFromNodeModules/package-exports-field/exports-directory/exports-directory.test.js +++ b/test/getImportMapFromProjectFiles/package-exports-field/exports-directory/exports-directory.test.js @@ -1,10 +1,10 @@ import { assert } from "@jsenv/assert" import { resolveUrl } from "@jsenv/util" -import { getImportMapFromNodeModules } from "@jsenv/node-module-import-map" +import { getImportMapFromProjectFiles } from "@jsenv/node-module-import-map" const testDirectoryUrl = resolveUrl("./", import.meta.url) -const actual = await getImportMapFromNodeModules({ +const actual = await getImportMapFromProjectFiles({ projectDirectoryUrl: testDirectoryUrl, packagesSelfReference: false, }) diff --git a/test/getImportMapFromNodeModules/package-exports-field/exports-directory/node_modules/@jsenv/whatever/index.js b/test/getImportMapFromProjectFiles/package-exports-field/exports-directory/node_modules/@jsenv/whatever/index.js similarity index 100% rename from test/getImportMapFromNodeModules/package-exports-field/exports-directory/node_modules/@jsenv/whatever/index.js rename to test/getImportMapFromProjectFiles/package-exports-field/exports-directory/node_modules/@jsenv/whatever/index.js diff --git a/test/getImportMapFromNodeModules/package-exports-field/exports-directory/node_modules/@jsenv/whatever/package.json b/test/getImportMapFromProjectFiles/package-exports-field/exports-directory/node_modules/@jsenv/whatever/package.json similarity index 100% rename from test/getImportMapFromNodeModules/package-exports-field/exports-directory/node_modules/@jsenv/whatever/package.json rename to test/getImportMapFromProjectFiles/package-exports-field/exports-directory/node_modules/@jsenv/whatever/package.json diff --git a/test/getImportMapFromNodeModules/package-exports-field/exports-directory/package.json b/test/getImportMapFromProjectFiles/package-exports-field/exports-directory/package.json similarity index 100% rename from test/getImportMapFromNodeModules/package-exports-field/exports-directory/package.json rename to test/getImportMapFromProjectFiles/package-exports-field/exports-directory/package.json diff --git a/test/getImportMapFromNodeModules/package-exports-field/exports-file-conditional/exports-file-conditional.test.js b/test/getImportMapFromProjectFiles/package-exports-field/exports-file-conditional/exports-file-conditional.test.js similarity index 81% rename from test/getImportMapFromNodeModules/package-exports-field/exports-file-conditional/exports-file-conditional.test.js rename to test/getImportMapFromProjectFiles/package-exports-field/exports-file-conditional/exports-file-conditional.test.js index 0426ad86..be67b1a3 100644 --- a/test/getImportMapFromNodeModules/package-exports-field/exports-file-conditional/exports-file-conditional.test.js +++ b/test/getImportMapFromProjectFiles/package-exports-field/exports-file-conditional/exports-file-conditional.test.js @@ -1,11 +1,11 @@ import { assert } from "@jsenv/assert" import { resolveUrl } from "@jsenv/util" -import { getImportMapFromNodeModules } from "@jsenv/node-module-import-map" +import { getImportMapFromProjectFiles } from "@jsenv/node-module-import-map" const testDirectoryUrl = resolveUrl("./", import.meta.url) { - const importMap = await getImportMapFromNodeModules({ + const importMap = await getImportMapFromProjectFiles({ projectDirectoryUrl: testDirectoryUrl, packagesExportsPreference: ["browser"], packagesSelfReference: false, @@ -22,7 +22,7 @@ const testDirectoryUrl = resolveUrl("./", import.meta.url) } { - const importMap = await getImportMapFromNodeModules({ + const importMap = await getImportMapFromProjectFiles({ projectDirectoryUrl: testDirectoryUrl, packagesExportsPreference: [], packagesSelfReference: false, diff --git a/test/getImportMapFromNodeModules/package-exports-field/exports-file-conditional/node_modules/foo/package.json b/test/getImportMapFromProjectFiles/package-exports-field/exports-file-conditional/node_modules/foo/package.json similarity index 100% rename from test/getImportMapFromNodeModules/package-exports-field/exports-file-conditional/node_modules/foo/package.json rename to test/getImportMapFromProjectFiles/package-exports-field/exports-file-conditional/node_modules/foo/package.json diff --git a/test/getImportMapFromNodeModules/package-exports-field/exports-file-conditional/package.json b/test/getImportMapFromProjectFiles/package-exports-field/exports-file-conditional/package.json similarity index 100% rename from test/getImportMapFromNodeModules/package-exports-field/exports-file-conditional/package.json rename to test/getImportMapFromProjectFiles/package-exports-field/exports-file-conditional/package.json diff --git a/test/getImportMapFromNodeModules/package-exports-field/exports-file-deep-2/exports-file-deep-2.test.js b/test/getImportMapFromProjectFiles/package-exports-field/exports-file-deep-2/exports-file-deep-2.test.js similarity index 83% rename from test/getImportMapFromNodeModules/package-exports-field/exports-file-deep-2/exports-file-deep-2.test.js rename to test/getImportMapFromProjectFiles/package-exports-field/exports-file-deep-2/exports-file-deep-2.test.js index 0c2c2bba..92e73588 100644 --- a/test/getImportMapFromNodeModules/package-exports-field/exports-file-deep-2/exports-file-deep-2.test.js +++ b/test/getImportMapFromProjectFiles/package-exports-field/exports-file-deep-2/exports-file-deep-2.test.js @@ -1,10 +1,10 @@ import { assert } from "@jsenv/assert" import { resolveUrl } from "@jsenv/util" -import { getImportMapFromNodeModules } from "@jsenv/node-module-import-map" +import { getImportMapFromProjectFiles } from "@jsenv/node-module-import-map" const testDirectoryUrl = resolveUrl("./", import.meta.url) -const importMap = await getImportMapFromNodeModules({ +const importMap = await getImportMapFromProjectFiles({ projectDirectoryUrl: testDirectoryUrl, packagesSelfReference: false, }) diff --git a/test/getImportMapFromNodeModules/package-exports-field/exports-file-deep-2/node_modules/foo/node_modules/bar/package.json b/test/getImportMapFromProjectFiles/package-exports-field/exports-file-deep-2/node_modules/foo/node_modules/bar/package.json similarity index 100% rename from test/getImportMapFromNodeModules/package-exports-field/exports-file-deep-2/node_modules/foo/node_modules/bar/package.json rename to test/getImportMapFromProjectFiles/package-exports-field/exports-file-deep-2/node_modules/foo/node_modules/bar/package.json diff --git a/test/getImportMapFromNodeModules/package-exports-field/exports-file-deep-2/node_modules/foo/package.json b/test/getImportMapFromProjectFiles/package-exports-field/exports-file-deep-2/node_modules/foo/package.json similarity index 100% rename from test/getImportMapFromNodeModules/package-exports-field/exports-file-deep-2/node_modules/foo/package.json rename to test/getImportMapFromProjectFiles/package-exports-field/exports-file-deep-2/node_modules/foo/package.json diff --git a/test/getImportMapFromNodeModules/package-exports-field/exports-file-deep-2/package.json b/test/getImportMapFromProjectFiles/package-exports-field/exports-file-deep-2/package.json similarity index 100% rename from test/getImportMapFromNodeModules/package-exports-field/exports-file-deep-2/package.json rename to test/getImportMapFromProjectFiles/package-exports-field/exports-file-deep-2/package.json diff --git a/test/getImportMapFromNodeModules/package-exports-field/exports-file-deep/exports-file-deep.test.js b/test/getImportMapFromProjectFiles/package-exports-field/exports-file-deep/exports-file-deep.test.js similarity index 81% rename from test/getImportMapFromNodeModules/package-exports-field/exports-file-deep/exports-file-deep.test.js rename to test/getImportMapFromProjectFiles/package-exports-field/exports-file-deep/exports-file-deep.test.js index 1cca4f12..071735dd 100644 --- a/test/getImportMapFromNodeModules/package-exports-field/exports-file-deep/exports-file-deep.test.js +++ b/test/getImportMapFromProjectFiles/package-exports-field/exports-file-deep/exports-file-deep.test.js @@ -1,10 +1,10 @@ import { assert } from "@jsenv/assert" import { resolveUrl } from "@jsenv/util" -import { getImportMapFromNodeModules } from "@jsenv/node-module-import-map" +import { getImportMapFromProjectFiles } from "@jsenv/node-module-import-map" const testDirectoryUrl = resolveUrl("./", import.meta.url) -const importMap = await getImportMapFromNodeModules({ +const importMap = await getImportMapFromProjectFiles({ projectDirectoryUrl: testDirectoryUrl, packagesSelfReference: false, }) diff --git a/test/getImportMapFromNodeModules/package-exports-field/exports-file-deep/node_modules/bar/package.json b/test/getImportMapFromProjectFiles/package-exports-field/exports-file-deep/node_modules/bar/package.json similarity index 100% rename from test/getImportMapFromNodeModules/package-exports-field/exports-file-deep/node_modules/bar/package.json rename to test/getImportMapFromProjectFiles/package-exports-field/exports-file-deep/node_modules/bar/package.json diff --git a/test/getImportMapFromNodeModules/package-exports-field/exports-file-deep/node_modules/foo/package.json b/test/getImportMapFromProjectFiles/package-exports-field/exports-file-deep/node_modules/foo/package.json similarity index 100% rename from test/getImportMapFromNodeModules/package-exports-field/exports-file-deep/node_modules/foo/package.json rename to test/getImportMapFromProjectFiles/package-exports-field/exports-file-deep/node_modules/foo/package.json diff --git a/test/getImportMapFromNodeModules/package-exports-field/exports-file-deep/package.json b/test/getImportMapFromProjectFiles/package-exports-field/exports-file-deep/package.json similarity index 100% rename from test/getImportMapFromNodeModules/package-exports-field/exports-file-deep/package.json rename to test/getImportMapFromProjectFiles/package-exports-field/exports-file-deep/package.json diff --git a/test/getImportMapFromNodeModules/package-exports-field/exports-file/exports-file.test.js b/test/getImportMapFromProjectFiles/package-exports-field/exports-file/exports-file.test.js similarity index 76% rename from test/getImportMapFromNodeModules/package-exports-field/exports-file/exports-file.test.js rename to test/getImportMapFromProjectFiles/package-exports-field/exports-file/exports-file.test.js index c9836785..91e3507a 100644 --- a/test/getImportMapFromNodeModules/package-exports-field/exports-file/exports-file.test.js +++ b/test/getImportMapFromProjectFiles/package-exports-field/exports-file/exports-file.test.js @@ -1,10 +1,10 @@ import { assert } from "@jsenv/assert" import { resolveUrl } from "@jsenv/util" -import { getImportMapFromNodeModules } from "@jsenv/node-module-import-map" +import { getImportMapFromProjectFiles } from "@jsenv/node-module-import-map" const testDirectoryUrl = resolveUrl("./", import.meta.url) -const importMap = await getImportMapFromNodeModules({ +const importMap = await getImportMapFromProjectFiles({ projectDirectoryUrl: testDirectoryUrl, packagesSelfReference: false, }) diff --git a/test/getImportMapFromNodeModules/package-exports-field/exports-file/node_modules/foo/index.js b/test/getImportMapFromProjectFiles/package-exports-field/exports-file/node_modules/foo/index.js similarity index 100% rename from test/getImportMapFromNodeModules/package-exports-field/exports-file/node_modules/foo/index.js rename to test/getImportMapFromProjectFiles/package-exports-field/exports-file/node_modules/foo/index.js diff --git a/test/getImportMapFromNodeModules/package-exports-field/exports-file/node_modules/foo/package.json b/test/getImportMapFromProjectFiles/package-exports-field/exports-file/node_modules/foo/package.json similarity index 100% rename from test/getImportMapFromNodeModules/package-exports-field/exports-file/node_modules/foo/package.json rename to test/getImportMapFromProjectFiles/package-exports-field/exports-file/node_modules/foo/package.json diff --git a/test/getImportMapFromNodeModules/package-exports-field/exports-file/package.json b/test/getImportMapFromProjectFiles/package-exports-field/exports-file/package.json similarity index 100% rename from test/getImportMapFromNodeModules/package-exports-field/exports-file/package.json rename to test/getImportMapFromProjectFiles/package-exports-field/exports-file/package.json diff --git a/test/getImportMapFromNodeModules/package-exports-field/exports-pattern-directory/exports-pattern-directory.test.js b/test/getImportMapFromProjectFiles/package-exports-field/exports-pattern-directory/exports-pattern-directory.test.js similarity index 74% rename from test/getImportMapFromNodeModules/package-exports-field/exports-pattern-directory/exports-pattern-directory.test.js rename to test/getImportMapFromProjectFiles/package-exports-field/exports-pattern-directory/exports-pattern-directory.test.js index 6036a0b1..e5acd03a 100644 --- a/test/getImportMapFromNodeModules/package-exports-field/exports-pattern-directory/exports-pattern-directory.test.js +++ b/test/getImportMapFromProjectFiles/package-exports-field/exports-pattern-directory/exports-pattern-directory.test.js @@ -1,10 +1,10 @@ import { assert } from "@jsenv/assert" import { resolveUrl } from "@jsenv/util" -import { getImportMapFromNodeModules } from "@jsenv/node-module-import-map" +import { getImportMapFromProjectFiles } from "@jsenv/node-module-import-map" const testDirectoryUrl = resolveUrl("./", import.meta.url) -const actual = await getImportMapFromNodeModules({ +const actual = await getImportMapFromProjectFiles({ projectDirectoryUrl: testDirectoryUrl, packagesSelfReference: false, }) diff --git a/test/getImportMapFromNodeModules/package-exports-field/exports-pattern-directory/node_modules/foo/package.json b/test/getImportMapFromProjectFiles/package-exports-field/exports-pattern-directory/node_modules/foo/package.json similarity index 100% rename from test/getImportMapFromNodeModules/package-exports-field/exports-pattern-directory/node_modules/foo/package.json rename to test/getImportMapFromProjectFiles/package-exports-field/exports-pattern-directory/node_modules/foo/package.json diff --git a/test/getImportMapFromNodeModules/package-exports-field/exports-pattern-directory/package.json b/test/getImportMapFromProjectFiles/package-exports-field/exports-pattern-directory/package.json similarity index 100% rename from test/getImportMapFromNodeModules/package-exports-field/exports-pattern-directory/package.json rename to test/getImportMapFromProjectFiles/package-exports-field/exports-pattern-directory/package.json diff --git a/test/getImportMapFromNodeModules/package-exports-field/exports-pattern-extensionless/exports-pattern-extensionless.test.js b/test/getImportMapFromProjectFiles/package-exports-field/exports-pattern-extensionless/exports-pattern-extensionless.test.js similarity index 72% rename from test/getImportMapFromNodeModules/package-exports-field/exports-pattern-extensionless/exports-pattern-extensionless.test.js rename to test/getImportMapFromProjectFiles/package-exports-field/exports-pattern-extensionless/exports-pattern-extensionless.test.js index 847df432..f108374b 100644 --- a/test/getImportMapFromNodeModules/package-exports-field/exports-pattern-extensionless/exports-pattern-extensionless.test.js +++ b/test/getImportMapFromProjectFiles/package-exports-field/exports-pattern-extensionless/exports-pattern-extensionless.test.js @@ -1,10 +1,10 @@ import { assert } from "@jsenv/assert" import { resolveUrl } from "@jsenv/util" -import { getImportMapFromNodeModules } from "@jsenv/node-module-import-map" +import { getImportMapFromProjectFiles } from "@jsenv/node-module-import-map" const testDirectoryUrl = resolveUrl("./", import.meta.url) -const actual = await getImportMapFromNodeModules({ +const actual = await getImportMapFromProjectFiles({ projectDirectoryUrl: testDirectoryUrl, packagesSelfReference: false, }) diff --git a/test/getImportMapFromNodeModules/package-exports-field/exports-pattern-extensionless/node_modules/foo/package.json b/test/getImportMapFromProjectFiles/package-exports-field/exports-pattern-extensionless/node_modules/foo/package.json similarity index 100% rename from test/getImportMapFromNodeModules/package-exports-field/exports-pattern-extensionless/node_modules/foo/package.json rename to test/getImportMapFromProjectFiles/package-exports-field/exports-pattern-extensionless/node_modules/foo/package.json diff --git a/test/getImportMapFromNodeModules/package-exports-field/exports-pattern-extensionless/package.json b/test/getImportMapFromProjectFiles/package-exports-field/exports-pattern-extensionless/package.json similarity index 100% rename from test/getImportMapFromNodeModules/package-exports-field/exports-pattern-extensionless/package.json rename to test/getImportMapFromProjectFiles/package-exports-field/exports-pattern-extensionless/package.json diff --git a/test/getImportMapFromNodeModules/package-exports-field/exports-string/exports-string.test.js b/test/getImportMapFromProjectFiles/package-exports-field/exports-string/exports-string.test.js similarity index 73% rename from test/getImportMapFromNodeModules/package-exports-field/exports-string/exports-string.test.js rename to test/getImportMapFromProjectFiles/package-exports-field/exports-string/exports-string.test.js index aa8e934f..ad58a847 100644 --- a/test/getImportMapFromNodeModules/package-exports-field/exports-string/exports-string.test.js +++ b/test/getImportMapFromProjectFiles/package-exports-field/exports-string/exports-string.test.js @@ -1,10 +1,10 @@ import { assert } from "@jsenv/assert" import { resolveUrl } from "@jsenv/util" -import { getImportMapFromNodeModules } from "@jsenv/node-module-import-map" +import { getImportMapFromProjectFiles } from "@jsenv/node-module-import-map" const testDirectoryUrl = resolveUrl("./", import.meta.url) -const importMap = await getImportMapFromNodeModules({ +const importMap = await getImportMapFromProjectFiles({ projectDirectoryUrl: testDirectoryUrl, packagesSelfReference: false, }) diff --git a/test/getImportMapFromNodeModules/package-exports-field/exports-string/node_modules/foo/package.json b/test/getImportMapFromProjectFiles/package-exports-field/exports-string/node_modules/foo/package.json similarity index 100% rename from test/getImportMapFromNodeModules/package-exports-field/exports-string/node_modules/foo/package.json rename to test/getImportMapFromProjectFiles/package-exports-field/exports-string/node_modules/foo/package.json diff --git a/test/getImportMapFromNodeModules/package-exports-field/exports-string/package.json b/test/getImportMapFromProjectFiles/package-exports-field/exports-string/package.json similarity index 100% rename from test/getImportMapFromNodeModules/package-exports-field/exports-string/package.json rename to test/getImportMapFromProjectFiles/package-exports-field/exports-string/package.json diff --git a/test/getImportMapFromNodeModules/package-exports-field/exports-sugar-conditional/exports-sugar-conditional.test.js b/test/getImportMapFromProjectFiles/package-exports-field/exports-sugar-conditional/exports-sugar-conditional.test.js similarity index 79% rename from test/getImportMapFromNodeModules/package-exports-field/exports-sugar-conditional/exports-sugar-conditional.test.js rename to test/getImportMapFromProjectFiles/package-exports-field/exports-sugar-conditional/exports-sugar-conditional.test.js index 842793b4..9d85bd49 100644 --- a/test/getImportMapFromNodeModules/package-exports-field/exports-sugar-conditional/exports-sugar-conditional.test.js +++ b/test/getImportMapFromProjectFiles/package-exports-field/exports-sugar-conditional/exports-sugar-conditional.test.js @@ -1,11 +1,11 @@ import { assert } from "@jsenv/assert" import { resolveUrl } from "@jsenv/util" -import { getImportMapFromNodeModules } from "@jsenv/node-module-import-map" +import { getImportMapFromProjectFiles } from "@jsenv/node-module-import-map" const testDirectoryUrl = resolveUrl("./", import.meta.url) { - const importMap = await getImportMapFromNodeModules({ + const importMap = await getImportMapFromProjectFiles({ projectDirectoryUrl: testDirectoryUrl, packagesExportsPreference: ["node"], packagesSelfReference: false, @@ -21,7 +21,7 @@ const testDirectoryUrl = resolveUrl("./", import.meta.url) } { - const importMap = await getImportMapFromNodeModules({ + const importMap = await getImportMapFromProjectFiles({ projectDirectoryUrl: testDirectoryUrl, packagesExportsPreference: ["browser"], packagesSelfReference: false, diff --git a/test/getImportMapFromNodeModules/package-exports-field/exports-sugar-conditional/node_modules/foo/package.json b/test/getImportMapFromProjectFiles/package-exports-field/exports-sugar-conditional/node_modules/foo/package.json similarity index 100% rename from test/getImportMapFromNodeModules/package-exports-field/exports-sugar-conditional/node_modules/foo/package.json rename to test/getImportMapFromProjectFiles/package-exports-field/exports-sugar-conditional/node_modules/foo/package.json diff --git a/test/getImportMapFromNodeModules/package-exports-field/exports-sugar-conditional/package.json b/test/getImportMapFromProjectFiles/package-exports-field/exports-sugar-conditional/package.json similarity index 100% rename from test/getImportMapFromNodeModules/package-exports-field/exports-sugar-conditional/package.json rename to test/getImportMapFromProjectFiles/package-exports-field/exports-sugar-conditional/package.json diff --git a/test/getImportMapFromNodeModules/package-exports-field/exports-sugar/exports-sugar.test.js b/test/getImportMapFromProjectFiles/package-exports-field/exports-sugar/exports-sugar.test.js similarity index 73% rename from test/getImportMapFromNodeModules/package-exports-field/exports-sugar/exports-sugar.test.js rename to test/getImportMapFromProjectFiles/package-exports-field/exports-sugar/exports-sugar.test.js index aa8e934f..ad58a847 100644 --- a/test/getImportMapFromNodeModules/package-exports-field/exports-sugar/exports-sugar.test.js +++ b/test/getImportMapFromProjectFiles/package-exports-field/exports-sugar/exports-sugar.test.js @@ -1,10 +1,10 @@ import { assert } from "@jsenv/assert" import { resolveUrl } from "@jsenv/util" -import { getImportMapFromNodeModules } from "@jsenv/node-module-import-map" +import { getImportMapFromProjectFiles } from "@jsenv/node-module-import-map" const testDirectoryUrl = resolveUrl("./", import.meta.url) -const importMap = await getImportMapFromNodeModules({ +const importMap = await getImportMapFromProjectFiles({ projectDirectoryUrl: testDirectoryUrl, packagesSelfReference: false, }) diff --git a/test/getImportMapFromNodeModules/package-exports-field/exports-sugar/node_modules/foo/package.json b/test/getImportMapFromProjectFiles/package-exports-field/exports-sugar/node_modules/foo/package.json similarity index 100% rename from test/getImportMapFromNodeModules/package-exports-field/exports-sugar/node_modules/foo/package.json rename to test/getImportMapFromProjectFiles/package-exports-field/exports-sugar/node_modules/foo/package.json diff --git a/test/getImportMapFromNodeModules/package-exports-field/exports-sugar/package.json b/test/getImportMapFromProjectFiles/package-exports-field/exports-sugar/package.json similarity index 100% rename from test/getImportMapFromNodeModules/package-exports-field/exports-sugar/package.json rename to test/getImportMapFromProjectFiles/package-exports-field/exports-sugar/package.json diff --git a/test/getImportMapFromNodeModules/package-main-field/main-directory-trailing/main-directory-trailing.test.js b/test/getImportMapFromProjectFiles/package-main-field/main-directory-trailing/main-directory-trailing.test.js similarity index 74% rename from test/getImportMapFromNodeModules/package-main-field/main-directory-trailing/main-directory-trailing.test.js rename to test/getImportMapFromProjectFiles/package-main-field/main-directory-trailing/main-directory-trailing.test.js index bfda6f64..90721172 100644 --- a/test/getImportMapFromNodeModules/package-main-field/main-directory-trailing/main-directory-trailing.test.js +++ b/test/getImportMapFromProjectFiles/package-main-field/main-directory-trailing/main-directory-trailing.test.js @@ -1,10 +1,10 @@ import { assert } from "@jsenv/assert" import { resolveUrl } from "@jsenv/util" -import { getImportMapFromNodeModules } from "@jsenv/node-module-import-map" +import { getImportMapFromProjectFiles } from "@jsenv/node-module-import-map" const testDirectoryUrl = resolveUrl("./", import.meta.url) -const actual = await getImportMapFromNodeModules({ +const actual = await getImportMapFromProjectFiles({ projectDirectoryUrl: testDirectoryUrl, packagesSelfReference: false, }) diff --git a/test/getImportMapFromNodeModules/package-main-field/main-directory-trailing/node_modules/main-folder-trailing/lib/index.js b/test/getImportMapFromProjectFiles/package-main-field/main-directory-trailing/node_modules/main-folder-trailing/lib/index.js similarity index 100% rename from test/getImportMapFromNodeModules/package-main-field/main-directory-trailing/node_modules/main-folder-trailing/lib/index.js rename to test/getImportMapFromProjectFiles/package-main-field/main-directory-trailing/node_modules/main-folder-trailing/lib/index.js diff --git a/test/getImportMapFromNodeModules/package-main-field/main-directory-trailing/node_modules/main-folder-trailing/package.json b/test/getImportMapFromProjectFiles/package-main-field/main-directory-trailing/node_modules/main-folder-trailing/package.json similarity index 100% rename from test/getImportMapFromNodeModules/package-main-field/main-directory-trailing/node_modules/main-folder-trailing/package.json rename to test/getImportMapFromProjectFiles/package-main-field/main-directory-trailing/node_modules/main-folder-trailing/package.json diff --git a/test/getImportMapFromNodeModules/package-main-field/main-directory-trailing/package.json b/test/getImportMapFromProjectFiles/package-main-field/main-directory-trailing/package.json similarity index 100% rename from test/getImportMapFromNodeModules/package-main-field/main-directory-trailing/package.json rename to test/getImportMapFromProjectFiles/package-main-field/main-directory-trailing/package.json diff --git a/test/getImportMapFromNodeModules/package-main-field/main-directory/main-directory.test.js b/test/getImportMapFromProjectFiles/package-main-field/main-directory/main-directory.test.js similarity index 73% rename from test/getImportMapFromNodeModules/package-main-field/main-directory/main-directory.test.js rename to test/getImportMapFromProjectFiles/package-main-field/main-directory/main-directory.test.js index e35c089c..2b5a9ac0 100644 --- a/test/getImportMapFromNodeModules/package-main-field/main-directory/main-directory.test.js +++ b/test/getImportMapFromProjectFiles/package-main-field/main-directory/main-directory.test.js @@ -1,10 +1,10 @@ import { assert } from "@jsenv/assert" import { resolveUrl } from "@jsenv/util" -import { getImportMapFromNodeModules } from "@jsenv/node-module-import-map" +import { getImportMapFromProjectFiles } from "@jsenv/node-module-import-map" const testDirectoryUrl = resolveUrl("./", import.meta.url) -const actual = await getImportMapFromNodeModules({ +const actual = await getImportMapFromProjectFiles({ projectDirectoryUrl: testDirectoryUrl, packagesSelfReference: false, }) diff --git a/test/getImportMapFromNodeModules/package-main-field/main-directory/node_modules/main-directory/lib/index.js b/test/getImportMapFromProjectFiles/package-main-field/main-directory/node_modules/main-directory/lib/index.js similarity index 100% rename from test/getImportMapFromNodeModules/package-main-field/main-directory/node_modules/main-directory/lib/index.js rename to test/getImportMapFromProjectFiles/package-main-field/main-directory/node_modules/main-directory/lib/index.js diff --git a/test/getImportMapFromNodeModules/package-main-field/main-directory/node_modules/main-directory/package.json b/test/getImportMapFromProjectFiles/package-main-field/main-directory/node_modules/main-directory/package.json similarity index 100% rename from test/getImportMapFromNodeModules/package-main-field/main-directory/node_modules/main-directory/package.json rename to test/getImportMapFromProjectFiles/package-main-field/main-directory/node_modules/main-directory/package.json diff --git a/test/getImportMapFromNodeModules/package-main-field/main-directory/package.json b/test/getImportMapFromProjectFiles/package-main-field/main-directory/package.json similarity index 100% rename from test/getImportMapFromNodeModules/package-main-field/main-directory/package.json rename to test/getImportMapFromProjectFiles/package-main-field/main-directory/package.json diff --git a/test/getImportMapFromNodeModules/package-main-field/main-jsnext/main-jsnext.test.js b/test/getImportMapFromProjectFiles/package-main-field/main-jsnext/main-jsnext.test.js similarity index 73% rename from test/getImportMapFromNodeModules/package-main-field/main-jsnext/main-jsnext.test.js rename to test/getImportMapFromProjectFiles/package-main-field/main-jsnext/main-jsnext.test.js index 43df5732..ca481cc6 100644 --- a/test/getImportMapFromNodeModules/package-main-field/main-jsnext/main-jsnext.test.js +++ b/test/getImportMapFromProjectFiles/package-main-field/main-jsnext/main-jsnext.test.js @@ -1,10 +1,10 @@ import { assert } from "@jsenv/assert" import { resolveUrl } from "@jsenv/util" -import { getImportMapFromNodeModules } from "@jsenv/node-module-import-map" +import { getImportMapFromProjectFiles } from "@jsenv/node-module-import-map" const testDirectoryUrl = resolveUrl("./", import.meta.url) -const actual = await getImportMapFromNodeModules({ +const actual = await getImportMapFromProjectFiles({ projectDirectoryUrl: testDirectoryUrl, packagesSelfReference: false, }) diff --git a/test/getImportMapFromNodeModules/package-main-field/main-jsnext/node_modules/main-jsnext/jsnext.js b/test/getImportMapFromProjectFiles/package-main-field/main-jsnext/node_modules/main-jsnext/jsnext.js similarity index 100% rename from test/getImportMapFromNodeModules/package-main-field/main-jsnext/node_modules/main-jsnext/jsnext.js rename to test/getImportMapFromProjectFiles/package-main-field/main-jsnext/node_modules/main-jsnext/jsnext.js diff --git a/test/getImportMapFromNodeModules/package-main-field/main-jsnext/node_modules/main-jsnext/package.json b/test/getImportMapFromProjectFiles/package-main-field/main-jsnext/node_modules/main-jsnext/package.json similarity index 100% rename from test/getImportMapFromNodeModules/package-main-field/main-jsnext/node_modules/main-jsnext/package.json rename to test/getImportMapFromProjectFiles/package-main-field/main-jsnext/node_modules/main-jsnext/package.json diff --git a/test/getImportMapFromNodeModules/package-main-field/main-jsnext/package.json b/test/getImportMapFromProjectFiles/package-main-field/main-jsnext/package.json similarity index 100% rename from test/getImportMapFromNodeModules/package-main-field/main-jsnext/package.json rename to test/getImportMapFromProjectFiles/package-main-field/main-jsnext/package.json diff --git a/test/getImportMapFromNodeModules/package-main-field/main-relative/main-relative.test.js b/test/getImportMapFromProjectFiles/package-main-field/main-relative/main-relative.test.js similarity index 73% rename from test/getImportMapFromNodeModules/package-main-field/main-relative/main-relative.test.js rename to test/getImportMapFromProjectFiles/package-main-field/main-relative/main-relative.test.js index da836443..75c6c93e 100644 --- a/test/getImportMapFromNodeModules/package-main-field/main-relative/main-relative.test.js +++ b/test/getImportMapFromProjectFiles/package-main-field/main-relative/main-relative.test.js @@ -1,10 +1,10 @@ import { assert } from "@jsenv/assert" import { resolveUrl } from "@jsenv/util" -import { getImportMapFromNodeModules } from "@jsenv/node-module-import-map" +import { getImportMapFromProjectFiles } from "@jsenv/node-module-import-map" const testDirectoryUrl = resolveUrl("./", import.meta.url) -const actual = await getImportMapFromNodeModules({ +const actual = await getImportMapFromProjectFiles({ projectDirectoryUrl: testDirectoryUrl, packagesSelfReference: false, }) diff --git a/test/getImportMapFromNodeModules/package-main-field/main-relative/node_modules/main-relative/lib/index.js b/test/getImportMapFromProjectFiles/package-main-field/main-relative/node_modules/main-relative/lib/index.js similarity index 100% rename from test/getImportMapFromNodeModules/package-main-field/main-relative/node_modules/main-relative/lib/index.js rename to test/getImportMapFromProjectFiles/package-main-field/main-relative/node_modules/main-relative/lib/index.js diff --git a/test/getImportMapFromNodeModules/package-main-field/main-relative/node_modules/main-relative/package.json b/test/getImportMapFromProjectFiles/package-main-field/main-relative/node_modules/main-relative/package.json similarity index 100% rename from test/getImportMapFromNodeModules/package-main-field/main-relative/node_modules/main-relative/package.json rename to test/getImportMapFromProjectFiles/package-main-field/main-relative/node_modules/main-relative/package.json diff --git a/test/getImportMapFromNodeModules/package-main-field/main-relative/package.json b/test/getImportMapFromProjectFiles/package-main-field/main-relative/package.json similarity index 100% rename from test/getImportMapFromNodeModules/package-main-field/main-relative/package.json rename to test/getImportMapFromProjectFiles/package-main-field/main-relative/package.json diff --git a/test/getImportMapFromNodeModules/package-main-field/main-undefined/main-undefined.test.js b/test/getImportMapFromProjectFiles/package-main-field/main-undefined/main-undefined.test.js similarity index 73% rename from test/getImportMapFromNodeModules/package-main-field/main-undefined/main-undefined.test.js rename to test/getImportMapFromProjectFiles/package-main-field/main-undefined/main-undefined.test.js index 863bfdbe..8b00db94 100644 --- a/test/getImportMapFromNodeModules/package-main-field/main-undefined/main-undefined.test.js +++ b/test/getImportMapFromProjectFiles/package-main-field/main-undefined/main-undefined.test.js @@ -1,10 +1,10 @@ import { assert } from "@jsenv/assert" import { resolveUrl } from "@jsenv/util" -import { getImportMapFromNodeModules } from "@jsenv/node-module-import-map" +import { getImportMapFromProjectFiles } from "@jsenv/node-module-import-map" const testDirectoryUrl = resolveUrl("./", import.meta.url) -const actual = await getImportMapFromNodeModules({ +const actual = await getImportMapFromProjectFiles({ projectDirectoryUrl: testDirectoryUrl, packagesSelfReference: false, }) diff --git a/test/getImportMapFromNodeModules/package-main-field/main-undefined/node_modules/main-undefined/index.js b/test/getImportMapFromProjectFiles/package-main-field/main-undefined/node_modules/main-undefined/index.js similarity index 100% rename from test/getImportMapFromNodeModules/package-main-field/main-undefined/node_modules/main-undefined/index.js rename to test/getImportMapFromProjectFiles/package-main-field/main-undefined/node_modules/main-undefined/index.js diff --git a/test/getImportMapFromNodeModules/package-main-field/main-undefined/node_modules/main-undefined/package.json b/test/getImportMapFromProjectFiles/package-main-field/main-undefined/node_modules/main-undefined/package.json similarity index 100% rename from test/getImportMapFromNodeModules/package-main-field/main-undefined/node_modules/main-undefined/package.json rename to test/getImportMapFromProjectFiles/package-main-field/main-undefined/node_modules/main-undefined/package.json diff --git a/test/getImportMapFromNodeModules/package-main-field/main-undefined/package.json b/test/getImportMapFromProjectFiles/package-main-field/main-undefined/package.json similarity index 100% rename from test/getImportMapFromNodeModules/package-main-field/main-undefined/package.json rename to test/getImportMapFromProjectFiles/package-main-field/main-undefined/package.json diff --git a/test/getImportMapFromNodeModules/package-main-field/main-without-extension/main-without-extension.test.js b/test/getImportMapFromProjectFiles/package-main-field/main-without-extension/main-without-extension.test.js similarity index 74% rename from test/getImportMapFromNodeModules/package-main-field/main-without-extension/main-without-extension.test.js rename to test/getImportMapFromProjectFiles/package-main-field/main-without-extension/main-without-extension.test.js index ee09712b..28264ee8 100644 --- a/test/getImportMapFromNodeModules/package-main-field/main-without-extension/main-without-extension.test.js +++ b/test/getImportMapFromProjectFiles/package-main-field/main-without-extension/main-without-extension.test.js @@ -1,10 +1,10 @@ import { assert } from "@jsenv/assert" import { resolveUrl } from "@jsenv/util" -import { getImportMapFromNodeModules } from "@jsenv/node-module-import-map" +import { getImportMapFromProjectFiles } from "@jsenv/node-module-import-map" const testDirectoryUrl = resolveUrl("./root/", import.meta.url) -const actual = await getImportMapFromNodeModules({ +const actual = await getImportMapFromProjectFiles({ projectDirectoryUrl: testDirectoryUrl, packagesSelfReference: false, }) diff --git a/test/getImportMapFromNodeModules/package-main-field/main-without-extension/root/node_modules/main-without-extension/file.js b/test/getImportMapFromProjectFiles/package-main-field/main-without-extension/root/node_modules/main-without-extension/file.js similarity index 100% rename from test/getImportMapFromNodeModules/package-main-field/main-without-extension/root/node_modules/main-without-extension/file.js rename to test/getImportMapFromProjectFiles/package-main-field/main-without-extension/root/node_modules/main-without-extension/file.js diff --git a/test/getImportMapFromNodeModules/package-main-field/main-without-extension/root/node_modules/main-without-extension/package.json b/test/getImportMapFromProjectFiles/package-main-field/main-without-extension/root/node_modules/main-without-extension/package.json similarity index 100% rename from test/getImportMapFromNodeModules/package-main-field/main-without-extension/root/node_modules/main-without-extension/package.json rename to test/getImportMapFromProjectFiles/package-main-field/main-without-extension/root/node_modules/main-without-extension/package.json diff --git a/test/getImportMapFromNodeModules/package-main-field/main-without-extension/root/package.json b/test/getImportMapFromProjectFiles/package-main-field/main-without-extension/root/package.json similarity index 100% rename from test/getImportMapFromNodeModules/package-main-field/main-without-extension/root/package.json rename to test/getImportMapFromProjectFiles/package-main-field/main-without-extension/root/package.json diff --git a/test/getImportMapFromNodeModules/self-import/self-import-1/index.js b/test/getImportMapFromProjectFiles/self-import/self-import-1/index.js similarity index 100% rename from test/getImportMapFromNodeModules/self-import/self-import-1/index.js rename to test/getImportMapFromProjectFiles/self-import/self-import-1/index.js diff --git a/test/getImportMapFromNodeModules/self-import/self-import-1/package.json b/test/getImportMapFromProjectFiles/self-import/self-import-1/package.json similarity index 100% rename from test/getImportMapFromNodeModules/self-import/self-import-1/package.json rename to test/getImportMapFromProjectFiles/self-import/self-import-1/package.json diff --git a/test/getImportMapFromNodeModules/self-import/self-import-1/self-import.test.js b/test/getImportMapFromProjectFiles/self-import/self-import-1/self-import.test.js similarity index 70% rename from test/getImportMapFromNodeModules/self-import/self-import-1/self-import.test.js rename to test/getImportMapFromProjectFiles/self-import/self-import-1/self-import.test.js index 8268c4be..fff01f28 100644 --- a/test/getImportMapFromNodeModules/self-import/self-import-1/self-import.test.js +++ b/test/getImportMapFromProjectFiles/self-import/self-import-1/self-import.test.js @@ -1,10 +1,10 @@ import { assert } from "@jsenv/assert" import { resolveUrl } from "@jsenv/util" -import { getImportMapFromNodeModules } from "@jsenv/node-module-import-map" +import { getImportMapFromProjectFiles } from "@jsenv/node-module-import-map" const testDirectoryUrl = resolveUrl("./", import.meta.url) -const actual = await getImportMapFromNodeModules({ +const actual = await getImportMapFromProjectFiles({ projectDirectoryUrl: testDirectoryUrl, }) const expected = { diff --git a/test/getImportMapFromNodeModules/self-import/self-import-2/index.js b/test/getImportMapFromProjectFiles/self-import/self-import-2/index.js similarity index 100% rename from test/getImportMapFromNodeModules/self-import/self-import-2/index.js rename to test/getImportMapFromProjectFiles/self-import/self-import-2/index.js diff --git a/test/getImportMapFromNodeModules/self-import/self-import-2/node_modules/foo/index.js b/test/getImportMapFromProjectFiles/self-import/self-import-2/node_modules/foo/index.js similarity index 100% rename from test/getImportMapFromNodeModules/self-import/self-import-2/node_modules/foo/index.js rename to test/getImportMapFromProjectFiles/self-import/self-import-2/node_modules/foo/index.js diff --git a/test/getImportMapFromNodeModules/self-import/self-import-2/node_modules/foo/package.json b/test/getImportMapFromProjectFiles/self-import/self-import-2/node_modules/foo/package.json similarity index 100% rename from test/getImportMapFromNodeModules/self-import/self-import-2/node_modules/foo/package.json rename to test/getImportMapFromProjectFiles/self-import/self-import-2/node_modules/foo/package.json diff --git a/test/getImportMapFromNodeModules/self-import/self-import-2/package.json b/test/getImportMapFromProjectFiles/self-import/self-import-2/package.json similarity index 100% rename from test/getImportMapFromNodeModules/self-import/self-import-2/package.json rename to test/getImportMapFromProjectFiles/self-import/self-import-2/package.json diff --git a/test/getImportMapFromNodeModules/self-import/self-import-2/self-import-2.test.js b/test/getImportMapFromProjectFiles/self-import/self-import-2/self-import-2.test.js similarity index 76% rename from test/getImportMapFromNodeModules/self-import/self-import-2/self-import-2.test.js rename to test/getImportMapFromProjectFiles/self-import/self-import-2/self-import-2.test.js index 0461022b..dae1a861 100644 --- a/test/getImportMapFromNodeModules/self-import/self-import-2/self-import-2.test.js +++ b/test/getImportMapFromProjectFiles/self-import/self-import-2/self-import-2.test.js @@ -1,10 +1,10 @@ import { assert } from "@jsenv/assert" import { resolveUrl } from "@jsenv/util" -import { getImportMapFromNodeModules } from "@jsenv/node-module-import-map" +import { getImportMapFromProjectFiles } from "@jsenv/node-module-import-map" const testDirectoryUrl = resolveUrl("./", import.meta.url) -const actual = await getImportMapFromNodeModules({ +const actual = await getImportMapFromProjectFiles({ projectDirectoryUrl: testDirectoryUrl, }) const expected = { diff --git a/test/getImportMapFromNodeModules/self-import/self-import-3/index.js b/test/getImportMapFromProjectFiles/self-import/self-import-3/index.js similarity index 100% rename from test/getImportMapFromNodeModules/self-import/self-import-3/index.js rename to test/getImportMapFromProjectFiles/self-import/self-import-3/index.js diff --git a/test/getImportMapFromNodeModules/self-import/self-import-3/node_modules/foo/package.json b/test/getImportMapFromProjectFiles/self-import/self-import-3/node_modules/foo/package.json similarity index 100% rename from test/getImportMapFromNodeModules/self-import/self-import-3/node_modules/foo/package.json rename to test/getImportMapFromProjectFiles/self-import/self-import-3/node_modules/foo/package.json diff --git a/test/getImportMapFromNodeModules/self-import/self-import-3/package.json b/test/getImportMapFromProjectFiles/self-import/self-import-3/package.json similarity index 100% rename from test/getImportMapFromNodeModules/self-import/self-import-3/package.json rename to test/getImportMapFromProjectFiles/self-import/self-import-3/package.json diff --git a/test/getImportMapFromNodeModules/self-import/self-import-3/self-import-3.test.js b/test/getImportMapFromProjectFiles/self-import/self-import-3/self-import-3.test.js similarity index 78% rename from test/getImportMapFromNodeModules/self-import/self-import-3/self-import-3.test.js rename to test/getImportMapFromProjectFiles/self-import/self-import-3/self-import-3.test.js index 0ce35586..d87cd14e 100644 --- a/test/getImportMapFromNodeModules/self-import/self-import-3/self-import-3.test.js +++ b/test/getImportMapFromProjectFiles/self-import/self-import-3/self-import-3.test.js @@ -1,10 +1,10 @@ import { assert } from "@jsenv/assert" import { resolveUrl } from "@jsenv/util" -import { getImportMapFromNodeModules } from "@jsenv/node-module-import-map" +import { getImportMapFromProjectFiles } from "@jsenv/node-module-import-map" const testDirectoryUrl = resolveUrl("./", import.meta.url) -const actual = await getImportMapFromNodeModules({ +const actual = await getImportMapFromProjectFiles({ projectDirectoryUrl: testDirectoryUrl, }) const expected = { diff --git a/test/getImportMapFromNodeModules/self-import/self-import-4/index.js b/test/getImportMapFromProjectFiles/self-import/self-import-4/index.js similarity index 100% rename from test/getImportMapFromNodeModules/self-import/self-import-4/index.js rename to test/getImportMapFromProjectFiles/self-import/self-import-4/index.js diff --git a/test/getImportMapFromNodeModules/self-import/self-import-4/node_modules/@jsenv/core/package.json b/test/getImportMapFromProjectFiles/self-import/self-import-4/node_modules/@jsenv/core/package.json similarity index 100% rename from test/getImportMapFromNodeModules/self-import/self-import-4/node_modules/@jsenv/core/package.json rename to test/getImportMapFromProjectFiles/self-import/self-import-4/node_modules/@jsenv/core/package.json diff --git a/test/getImportMapFromNodeModules/self-import/self-import-4/package.json b/test/getImportMapFromProjectFiles/self-import/self-import-4/package.json similarity index 100% rename from test/getImportMapFromNodeModules/self-import/self-import-4/package.json rename to test/getImportMapFromProjectFiles/self-import/self-import-4/package.json diff --git a/test/getImportMapFromNodeModules/self-import/self-import-4/self-import-4.test.js b/test/getImportMapFromProjectFiles/self-import/self-import-4/self-import-4.test.js similarity index 78% rename from test/getImportMapFromNodeModules/self-import/self-import-4/self-import-4.test.js rename to test/getImportMapFromProjectFiles/self-import/self-import-4/self-import-4.test.js index ef8b15bd..acd8d57f 100644 --- a/test/getImportMapFromNodeModules/self-import/self-import-4/self-import-4.test.js +++ b/test/getImportMapFromProjectFiles/self-import/self-import-4/self-import-4.test.js @@ -1,10 +1,10 @@ import { assert } from "@jsenv/assert" import { resolveUrl } from "@jsenv/util" -import { getImportMapFromNodeModules } from "@jsenv/node-module-import-map" +import { getImportMapFromProjectFiles } from "@jsenv/node-module-import-map" const testDirectoryUrl = resolveUrl("./", import.meta.url) -const actual = await getImportMapFromNodeModules({ +const actual = await getImportMapFromProjectFiles({ projectDirectoryUrl: testDirectoryUrl, projectPackageDevDependenciesIncluded: true, }) diff --git a/test/getImportMapFromNodeModules/self-import/self-import-5/node_modules/@jsenv/core/package.json b/test/getImportMapFromProjectFiles/self-import/self-import-5/node_modules/@jsenv/core/package.json similarity index 100% rename from test/getImportMapFromNodeModules/self-import/self-import-5/node_modules/@jsenv/core/package.json rename to test/getImportMapFromProjectFiles/self-import/self-import-5/node_modules/@jsenv/core/package.json diff --git a/test/getImportMapFromNodeModules/self-import/self-import-5/package.json b/test/getImportMapFromProjectFiles/self-import/self-import-5/package.json similarity index 100% rename from test/getImportMapFromNodeModules/self-import/self-import-5/package.json rename to test/getImportMapFromProjectFiles/self-import/self-import-5/package.json diff --git a/test/getImportMapFromNodeModules/self-import/self-import-5/self-import-5.test.js b/test/getImportMapFromProjectFiles/self-import/self-import-5/self-import-5.test.js similarity index 78% rename from test/getImportMapFromNodeModules/self-import/self-import-5/self-import-5.test.js rename to test/getImportMapFromProjectFiles/self-import/self-import-5/self-import-5.test.js index e5dd137f..82d1e9a9 100644 --- a/test/getImportMapFromNodeModules/self-import/self-import-5/self-import-5.test.js +++ b/test/getImportMapFromProjectFiles/self-import/self-import-5/self-import-5.test.js @@ -1,10 +1,10 @@ import { assert } from "@jsenv/assert" import { resolveUrl } from "@jsenv/util" -import { getImportMapFromNodeModules } from "@jsenv/node-module-import-map" +import { getImportMapFromProjectFiles } from "@jsenv/node-module-import-map" const testDirectoryUrl = resolveUrl("./", import.meta.url) -const actual = await getImportMapFromNodeModules({ +const actual = await getImportMapFromProjectFiles({ projectDirectoryUrl: testDirectoryUrl, projectPackageDevDependenciesIncluded: true, }) diff --git a/test/getImportMapFromNodeModules/self-import/self-import-6/root/node_modules/@jsenv/core/package.json b/test/getImportMapFromProjectFiles/self-import/self-import-6/root/node_modules/@jsenv/core/package.json similarity index 100% rename from test/getImportMapFromNodeModules/self-import/self-import-6/root/node_modules/@jsenv/core/package.json rename to test/getImportMapFromProjectFiles/self-import/self-import-6/root/node_modules/@jsenv/core/package.json diff --git a/test/getImportMapFromNodeModules/self-import/self-import-6/root/package.json b/test/getImportMapFromProjectFiles/self-import/self-import-6/root/package.json similarity index 100% rename from test/getImportMapFromNodeModules/self-import/self-import-6/root/package.json rename to test/getImportMapFromProjectFiles/self-import/self-import-6/root/package.json diff --git a/test/getImportMapFromNodeModules/self-import/self-import-6/self-import-6.test.js b/test/getImportMapFromProjectFiles/self-import/self-import-6/self-import-6.test.js similarity index 85% rename from test/getImportMapFromNodeModules/self-import/self-import-6/self-import-6.test.js rename to test/getImportMapFromProjectFiles/self-import/self-import-6/self-import-6.test.js index e1f7a7e6..747f403e 100644 --- a/test/getImportMapFromNodeModules/self-import/self-import-6/self-import-6.test.js +++ b/test/getImportMapFromProjectFiles/self-import/self-import-6/self-import-6.test.js @@ -1,10 +1,10 @@ import { assert } from "@jsenv/assert" import { resolveUrl } from "@jsenv/util" -import { getImportMapFromNodeModules } from "@jsenv/node-module-import-map" +import { getImportMapFromProjectFiles } from "@jsenv/node-module-import-map" const testDirectoryUrl = resolveUrl("./root/", import.meta.url) -const actual = await getImportMapFromNodeModules({ +const actual = await getImportMapFromProjectFiles({ projectDirectoryUrl: testDirectoryUrl, dev: true, }) From b8b4b649723f65d8f41f2eea3d203f8aa3844359 Mon Sep 17 00:00:00 2001 From: Damien Maillard Date: Sun, 7 Mar 2021 10:16:55 +0100 Subject: [PATCH 12/36] rename target into runtime --- script/generate-import-map/generate-import-map.js | 2 +- .../exports-condition-nested/exports-condition-nested.test.js | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/script/generate-import-map/generate-import-map.js b/script/generate-import-map/generate-import-map.js index 0185613e..5f63f4ee 100644 --- a/script/generate-import-map/generate-import-map.js +++ b/script/generate-import-map/generate-import-map.js @@ -8,7 +8,7 @@ generateImportMapForProject( [ getImportMapFromProjectFiles({ projectDirectoryUrl, - target: "node", + runtime: "node", dev: true, }), ], diff --git a/test/getImportMapFromProjectFiles/package-exports-field/exports-condition-nested/exports-condition-nested.test.js b/test/getImportMapFromProjectFiles/package-exports-field/exports-condition-nested/exports-condition-nested.test.js index 98592d66..a3a29b48 100644 --- a/test/getImportMapFromProjectFiles/package-exports-field/exports-condition-nested/exports-condition-nested.test.js +++ b/test/getImportMapFromProjectFiles/package-exports-field/exports-condition-nested/exports-condition-nested.test.js @@ -7,7 +7,7 @@ const testDirectoryUrl = resolveUrl("./root/", import.meta.url) { const importMap = await getImportMapFromProjectFiles({ projectDirectoryUrl: testDirectoryUrl, - target: "node", + runtime: "node", packagesSelfReference: false, }) const actual = importMap @@ -23,7 +23,7 @@ const testDirectoryUrl = resolveUrl("./root/", import.meta.url) { const importMap = await getImportMapFromProjectFiles({ projectDirectoryUrl: testDirectoryUrl, - target: "browser", + runtime: "browser", packagesSelfReference: false, }) const actual = importMap From d206716c0494b435c67ca2c2801d77ce3d1d7017 Mon Sep 17 00:00:00 2001 From: Damien Maillard Date: Sun, 7 Mar 2021 19:18:46 +0100 Subject: [PATCH 13/36] remove root directory url concept + move functions --- .../getImportMapFromPackageFiles.js | 110 ++++++++---------- .../from-package/resolveNodeModule.js | 73 ------------ 2 files changed, 47 insertions(+), 136 deletions(-) delete mode 100644 src/internal/from-package/resolveNodeModule.js diff --git a/src/internal/from-package/getImportMapFromPackageFiles.js b/src/internal/from-package/getImportMapFromPackageFiles.js index 6dd0b2bb..78e93100 100644 --- a/src/internal/from-package/getImportMapFromPackageFiles.js +++ b/src/internal/from-package/getImportMapFromPackageFiles.js @@ -10,6 +10,7 @@ import { import { resolvePackageMain } from "./resolvePackageMain.js" import { visitPackageExports } from "./visitPackageExports.js" import { createFindNodeModulePackage } from "./node-module-resolution.js" +// import { visitPackageImportMap } from "./visitPackageImportmap.js" export const getImportMapFromPackageFiles = async ({ // nothing is actually listening for this cancellationToken for now @@ -18,8 +19,6 @@ export const getImportMapFromPackageFiles = async ({ // cancellationToken = createCancellationTokenForProcess(), logLevel, projectDirectoryUrl, - rootProjectDirectoryUrl, - projectPackageDevDependenciesIncluded = process.env.NODE_ENV !== "production", packagesExportsPreference = ["import", "browser"], packagesExportsIncluded = true, @@ -30,20 +29,40 @@ export const getImportMapFromPackageFiles = async ({ const logger = createLogger({ logLevel }) projectDirectoryUrl = assertAndNormalizeDirectoryUrl(projectDirectoryUrl) - if (typeof rootProjectDirectoryUrl === "undefined") { - rootProjectDirectoryUrl = projectDirectoryUrl - } else { - rootProjectDirectoryUrl = assertAndNormalizeDirectoryUrl(rootProjectDirectoryUrl) - } const projectPackageFileUrl = resolveUrl("./package.json", projectDirectoryUrl) - const rootProjectPackageFileUrl = resolveUrl("./package.json", rootProjectDirectoryUrl) const findNodeModulePackage = createFindNodeModulePackage(packagesManualOverrides) const imports = {} const scopes = {} - const seen = {} + const addTopLevelImportMapping = ({ from, to }) => { + // we could think it's useless to remap from with to + // however it can be used to ensure a weaker remapping + // does not win over this specific file or folder + if (from === to) { + /** + * however remapping '/' to '/' is truly useless + * moreover it would make wrapImportMap create something like + * { + * imports: { + * "/": "/.dist/best/" + * } + * } + * that would append the wrapped folder twice + * */ + if (from === "/") return + } + imports[from] = to + } + const addScopedImportMapping = ({ scope, from, to }) => { + scopes[scope] = { + ...(scopes[scope] || {}), + [from]: to, + } + } + + const seen = {} const markPackageAsSeen = (packageFileUrl, importerPackageFileUrl) => { if (packageFileUrl in seen) { seen[packageFileUrl].push(importerPackageFileUrl) @@ -51,7 +70,6 @@ export const getImportMapFromPackageFiles = async ({ seen[packageFileUrl] = [importerPackageFileUrl] } } - const packageIsSeen = (packageFileUrl, importerPackageFileUrl) => { return packageFileUrl in seen && seen[packageFileUrl].includes(importerPackageFileUrl) } @@ -102,6 +120,13 @@ export const getImportMapFromPackageFiles = async ({ packageInfo, }) + // const importsForPackageImportmap = await visitPackageImportMap({ + // logger, + // packageFileUrl, + // packageJsonObject, + // projectDirectoryUrl, + // }) + if (packagesSelfReference) { const { packageIsRoot, packageDirectoryRelativeUrl } = packageInfo @@ -236,13 +261,14 @@ export const getImportMapFromPackageFiles = async ({ importerIsRoot, importerRelativeUrl, packageIsRoot, - packageIsProject, packageDirectoryUrl, packageDirectoryUrlExpected, }, }) => { - const self = packageIsRoot || packageIsProject - if (self && !packagesSelfReference) return + const self = packageIsRoot + if (self && !packagesSelfReference) { + return + } const mainFileUrl = await resolvePackageMain({ packageFileUrl, @@ -255,7 +281,7 @@ export const getImportMapFromPackageFiles = async ({ // or a main that does not lead to an actual file if (mainFileUrl === null) return - const mainFileRelativeUrl = urlToRelativeUrl(mainFileUrl, rootProjectDirectoryUrl) + const mainFileRelativeUrl = urlToRelativeUrl(mainFileUrl, projectDirectoryUrl) const from = packageName const to = `./${mainFileRelativeUrl}` @@ -332,74 +358,32 @@ export const getImportMapFromPackageFiles = async ({ } const computePackageInfo = ({ packageFileUrl, packageName, importerPackageFileUrl }) => { - const importerIsRoot = importerPackageFileUrl === rootProjectPackageFileUrl - - const importerIsProject = importerPackageFileUrl === projectPackageFileUrl + const importerIsRoot = importerPackageFileUrl === projectPackageFileUrl const importerPackageDirectoryUrl = resolveUrl("./", importerPackageFileUrl) const importerRelativeUrl = importerIsRoot - ? `${urlToBasename(rootProjectDirectoryUrl.slice(0, -1))}/` - : urlToRelativeUrl(importerPackageDirectoryUrl, rootProjectDirectoryUrl) - - const packageIsRoot = packageFileUrl === rootProjectPackageFileUrl + ? `${urlToBasename(projectDirectoryUrl.slice(0, -1))}/` + : urlToRelativeUrl(importerPackageDirectoryUrl, projectDirectoryUrl) - const packageIsProject = packageFileUrl === projectPackageFileUrl + const packageIsRoot = packageFileUrl === projectPackageFileUrl const packageDirectoryUrl = resolveUrl("./", packageFileUrl) - let packageDirectoryUrlExpected - if (packageIsProject && !packageIsRoot) { - packageDirectoryUrlExpected = importerPackageDirectoryUrl - } else { - packageDirectoryUrlExpected = `${importerPackageDirectoryUrl}node_modules/${packageName}/` - } + const packageDirectoryUrlExpected = `${importerPackageDirectoryUrl}node_modules/${packageName}/` - const packageDirectoryRelativeUrl = urlToRelativeUrl( - packageDirectoryUrl, - rootProjectDirectoryUrl, - ) + const packageDirectoryRelativeUrl = urlToRelativeUrl(packageDirectoryUrl, projectDirectoryUrl) return { importerIsRoot, - importerIsProject, importerRelativeUrl, packageIsRoot, - packageIsProject, packageDirectoryUrl, packageDirectoryUrlExpected, packageDirectoryRelativeUrl, } } - const addTopLevelImportMapping = ({ from, to }) => { - // we could think it's useless to remap from with to - // however it can be used to ensure a weaker remapping - // does not win over this specific file or folder - if (from === to) { - /** - * however remapping '/' to '/' is truly useless - * moreover it would make wrapImportMap create something like - * { - * imports: { - * "/": "/.dist/best/" - * } - * } - * that would append the wrapped folder twice - * */ - if (from === "/") return - } - - imports[from] = to - } - - const addScopedImportMapping = ({ scope, from, to }) => { - scopes[scope] = { - ...(scopes[scope] || {}), - [from]: to, - } - } - const dependenciesCache = {} const findDependency = ({ packageFileUrl, dependencyName }) => { if (packageFileUrl in dependenciesCache === false) { @@ -409,7 +393,7 @@ export const getImportMapFromPackageFiles = async ({ return dependenciesCache[packageFileUrl][dependencyName] } const dependencyPromise = findNodeModulePackage({ - projectDirectoryUrl: rootProjectDirectoryUrl, + projectDirectoryUrl, packageFileUrl, dependencyName, }) diff --git a/src/internal/from-package/resolveNodeModule.js b/src/internal/from-package/resolveNodeModule.js deleted file mode 100644 index 758daf1f..00000000 --- a/src/internal/from-package/resolveNodeModule.js +++ /dev/null @@ -1,73 +0,0 @@ -import { firstOperationMatching } from "@jsenv/cancellation" -import { urlToRelativeUrl, resolveUrl, urlToFileSystemPath } from "@jsenv/util" -import { readPackageFile } from "./readPackageFile.js" - -export const resolveNodeModule = async ({ - logger, - rootProjectDirectoryUrl, - packagesManualOverrides, - packageFileUrl, - dependencyName, -}) => { - const packageDirectoryUrl = resolveUrl("./", packageFileUrl) - const nodeModuleCandidateArray = [ - ...computeNodeModuleCandidateArray(packageDirectoryUrl, rootProjectDirectoryUrl), - `node_modules/`, - ] - - return firstOperationMatching({ - array: nodeModuleCandidateArray, - start: async (nodeModuleCandidate) => { - const packageFileUrl = `${rootProjectDirectoryUrl}${nodeModuleCandidate}${dependencyName}/package.json` - try { - const packageJsonObject = await readPackageFile(packageFileUrl, packagesManualOverrides) - return { - packageFileUrl, - packageJsonObject, - } - } catch (e) { - if (e.code === "ENOENT") { - return {} - } - - if (e.name === "SyntaxError") { - logger.error(` -error while parsing dependency package.json. ---- parsing error message --- -${e.message} ---- package.json path --- -${urlToFileSystemPath(packageFileUrl)} -`) - return {} - } - - throw e - } - }, - predicate: ({ packageJsonObject }) => Boolean(packageJsonObject), - }) -} - -const computeNodeModuleCandidateArray = (packageDirectoryUrl, rootProjectDirectoryUrl) => { - if (packageDirectoryUrl === rootProjectDirectoryUrl) { - return [] - } - - const packageDirectoryRelativeUrl = urlToRelativeUrl(packageDirectoryUrl, rootProjectDirectoryUrl) - - const candidateArray = [] - const relativeNodeModuleDirectoryArray = packageDirectoryRelativeUrl.split("node_modules/") - // remove the first empty string - relativeNodeModuleDirectoryArray.shift() - - let i = relativeNodeModuleDirectoryArray.length - while (i--) { - candidateArray.push( - `node_modules/${relativeNodeModuleDirectoryArray - .slice(0, i + 1) - .join("node_modules/")}node_modules/`, - ) - } - - return candidateArray -} From 844913d6217b4a26940d61a4a49d211436d17105 Mon Sep 17 00:00:00 2001 From: Damien Maillard Date: Sun, 7 Mar 2021 19:52:00 +0100 Subject: [PATCH 14/36] reorg some code --- .../getImportMapFromPackageFiles.js | 158 ++++++++++-------- 1 file changed, 88 insertions(+), 70 deletions(-) diff --git a/src/internal/from-package/getImportMapFromPackageFiles.js b/src/internal/from-package/getImportMapFromPackageFiles.js index 78e93100..96ecd8e9 100644 --- a/src/internal/from-package/getImportMapFromPackageFiles.js +++ b/src/internal/from-package/getImportMapFromPackageFiles.js @@ -10,7 +10,6 @@ import { import { resolvePackageMain } from "./resolvePackageMain.js" import { visitPackageExports } from "./visitPackageExports.js" import { createFindNodeModulePackage } from "./node-module-resolution.js" -// import { visitPackageImportMap } from "./visitPackageImportmap.js" export const getImportMapFromPackageFiles = async ({ // nothing is actually listening for this cancellationToken for now @@ -56,6 +55,24 @@ export const getImportMapFromPackageFiles = async ({ imports[from] = to } const addScopedImportMapping = ({ scope, from, to }) => { + // when a package says './' maps to './' + // we must add something to say if we are already inside the package + // no need to ensure leading slash are scoped to the package + if (from === "./" && to === "./") { + addScopedImportMapping({ + scope, + from: scope, + to: scope, + }) + } + if (from === "/" && to === "/") { + addScopedImportMapping({ + scope, + from, + to, + }) + } + scopes[scope] = { ...(scopes[scope] || {}), [from]: to, @@ -120,12 +137,72 @@ export const getImportMapFromPackageFiles = async ({ packageInfo, }) - // const importsForPackageImportmap = await visitPackageImportMap({ - // logger, - // packageFileUrl, - // packageJsonObject, - // projectDirectoryUrl, - // }) + const { + importerIsRoot, + importerRelativeUrl, + packageIsRoot, + packageDirectoryRelativeUrl, + // packageDirectoryUrl, + // packageDirectoryUrlExpected, + } = packageInfo + + const addMappingsForPackageAndImporter = (mappings) => { + if (packageIsRoot) { + if (!packagesSelfReference) { + // ignore exports + return + } + + Object.keys(mappings).forEach((from) => { + const to = mappings[from] + addTopLevelImportMapping({ + from, + to, + }) + }) + return + } + + if (importerIsRoot) { + // own package mappings available to himself + Object.keys(mappings).forEach((from) => { + const to = mappings[from] + // importer is the package himself, keep exports scoped + // otherwise the dependency mappings would override the importer mappings. + if (importerPackageJsonObject.name === packageName) { + addScopedImportMapping({ + scope: `./${packageDirectoryRelativeUrl}`, + from, + to, + }) + if (from === packageName || from in imports === false) { + addTopLevelImportMapping({ from, to }) + } + } else { + addTopLevelImportMapping({ from, to }) + } + }) + + // if importer is root no need to make package mappings available to the importer + // because they are already on top level mappings + return + } + + Object.keys(mappings).forEach((from) => { + const to = mappings[from] + + // own package exports available to himself + addScopedImportMapping({ + scope: `./${packageDirectoryRelativeUrl}`, + from, + to, + }) + // now make package exports available to the importer + // here if the importer is himself we could do stuff + // we should even handle the case earlier to prevent top level remapping + addScopedImportMapping({ scope: `./${importerRelativeUrl}`, from, to }) + }) + } if (packagesSelfReference) { const { packageIsRoot, packageDirectoryRelativeUrl } = packageInfo @@ -148,7 +225,7 @@ export const getImportMapFromPackageFiles = async ({ } if (packagesExportsIncluded && "exports" in packageJsonObject) { - const importsForPackageExports = {} + const mappingsFromPackageExports = {} visitPackageExports({ packageFileUrl, packageJsonObject, @@ -160,7 +237,7 @@ export const getImportMapFromPackageFiles = async ({ const to = value if (from.indexOf("*") === -1) { - importsForPackageExports[from] = to + mappingsFromPackageExports[from] = to return } @@ -172,7 +249,7 @@ export const getImportMapFromPackageFiles = async ({ ) { const fromWithouTrailingStar = from.slice(0, -1) const toWithoutTrailingStar = to.slice(0, -1) - importsForPackageExports[fromWithouTrailingStar] = toWithoutTrailingStar + mappingsFromPackageExports[fromWithouTrailingStar] = toWithoutTrailingStar return } @@ -190,66 +267,7 @@ export const getImportMapFromPackageFiles = async ({ `) }, }) - - const { - importerIsRoot, - importerRelativeUrl, - packageIsRoot, - packageDirectoryRelativeUrl, - // packageDirectoryUrl, - // packageDirectoryUrlExpected, - } = packageInfo - - if (packageIsRoot && packagesSelfReference) { - Object.keys(importsForPackageExports).forEach((from) => { - const to = importsForPackageExports[from] - addTopLevelImportMapping({ - from, - to, - }) - }) - } else if (packageIsRoot) { - // ignore exports - } else { - Object.keys(importsForPackageExports).forEach((from) => { - const to = importsForPackageExports[from] - - // own package exports available to himself - if (importerIsRoot) { - // importer is the package himself, keep exports scoped - // otherwise the dependency exports would override the package exports. - if (importerPackageJsonObject.name === packageName) { - addScopedImportMapping({ - scope: `./${packageDirectoryRelativeUrl}`, - from, - to, - }) - if (from === packageName || from in imports === false) { - addTopLevelImportMapping({ from, to }) - } - } else { - addTopLevelImportMapping({ from, to }) - } - } else { - addScopedImportMapping({ - scope: `./${packageDirectoryRelativeUrl}`, - from, - to, - }) - } - - // now make package exports available to the importer - // if importer is root no need because the top level remapping does it - if (importerIsRoot) { - return - } - - // now make it available to the importer - // here if the importer is himself we could do stuff - // we should even handle the case earlier to prevent top level remapping - addScopedImportMapping({ scope: `./${importerRelativeUrl}`, from, to }) - }) - } + addMappingsForPackageAndImporter(mappingsFromPackageExports) } } From 2f929497f04d10331cd8935067ffc1bdfce671b6 Mon Sep 17 00:00:00 2001 From: Damien Maillard Date: Sun, 7 Mar 2021 20:21:28 +0100 Subject: [PATCH 15/36] handle importmap field --- .../getImportMapFromPackageFiles.js | 82 +++++++++++++++++-- .../from-package/visitPackageImportMap.js | 40 +++++++++ .../root/node_modules/bar/package.json | 6 +- .../root/node_modules/foo/package.json | 6 +- .../importmap-scope/importmap-scope.test.js | 21 +++++ .../root/node_modules/foo/package.json | 10 +++ .../importmap-scope/root/package.json | 6 ++ .../importmap-top-level.test.js | 21 +++++ .../root/node_modules/foo/package.json | 8 ++ .../importmap-top-level/root/package.json | 6 ++ 10 files changed, 194 insertions(+), 12 deletions(-) create mode 100644 src/internal/from-package/visitPackageImportMap.js create mode 100644 test/getImportMapFromProjectFiles/package-importmap-field/importmap-scope/importmap-scope.test.js create mode 100644 test/getImportMapFromProjectFiles/package-importmap-field/importmap-scope/root/node_modules/foo/package.json create mode 100644 test/getImportMapFromProjectFiles/package-importmap-field/importmap-scope/root/package.json create mode 100644 test/getImportMapFromProjectFiles/package-importmap-field/importmap-top-level/importmap-top-level.test.js create mode 100644 test/getImportMapFromProjectFiles/package-importmap-field/importmap-top-level/root/node_modules/foo/package.json create mode 100644 test/getImportMapFromProjectFiles/package-importmap-field/importmap-top-level/root/package.json diff --git a/src/internal/from-package/getImportMapFromPackageFiles.js b/src/internal/from-package/getImportMapFromPackageFiles.js index 96ecd8e9..921dbcab 100644 --- a/src/internal/from-package/getImportMapFromPackageFiles.js +++ b/src/internal/from-package/getImportMapFromPackageFiles.js @@ -8,6 +8,7 @@ import { readFile, } from "@jsenv/util" import { resolvePackageMain } from "./resolvePackageMain.js" +import { visitPackageImportMap } from "./visitPackageImportMap.js" import { visitPackageExports } from "./visitPackageExports.js" import { createFindNodeModulePackage } from "./node-module-resolution.js" @@ -58,20 +59,13 @@ export const getImportMapFromPackageFiles = async ({ // when a package says './' maps to './' // we must add something to say if we are already inside the package // no need to ensure leading slash are scoped to the package - if (from === "./" && to === "./") { + if (from === "./" && to === scope) { addScopedImportMapping({ scope, from: scope, to: scope, }) } - if (from === "/" && to === "/") { - addScopedImportMapping({ - scope, - from, - to, - }) - } scopes[scope] = { ...(scopes[scope] || {}), @@ -146,6 +140,54 @@ export const getImportMapFromPackageFiles = async ({ // packageDirectoryUrlExpected, } = packageInfo + const addImportMapForPackage = (importMap) => { + if (packageIsRoot) { + const { imports = {}, scopes = {} } = importMap + Object.keys(imports).forEach((from) => { + addTopLevelImportMapping({ + from, + to: imports[from], + }) + }) + Object.keys(scopes).forEach((scope) => { + const scopeMappings = scopes[scope] + Object.keys(scopeMappings).forEach((key) => { + addScopedImportMapping({ + scope, + from: key, + to: scopeMappings[key], + }) + }) + }) + return + } + + const { imports = {}, scopes = {} } = importMap + const scope = `./${packageDirectoryRelativeUrl}` + Object.keys(imports).forEach((from) => { + const to = imports[from] + const toMoved = moveMappingValue(to, packageFileUrl, projectDirectoryUrl) + addScopedImportMapping({ + scope, + from, + to: toMoved, + }) + }) + Object.keys(scopes).forEach((scope) => { + const scopeMappings = scopes[scope] + const scopeMoved = moveMappingValue(scope, packageFileUrl, projectDirectoryUrl) + Object.keys(scopeMappings).forEach((key) => { + const to = scopeMappings[key] + const toMoved = moveMappingValue(to, packageFileUrl, projectDirectoryUrl) + addScopedImportMapping({ + scope: scopeMoved, + from: key, + to: toMoved, + }) + }) + }) + } + const addMappingsForPackageAndImporter = (mappings) => { if (packageIsRoot) { if (!packagesSelfReference) { @@ -204,6 +246,14 @@ export const getImportMapFromPackageFiles = async ({ }) } + const importsFromPackageField = await visitPackageImportMap({ + logger, + packageFileUrl, + packageJsonObject, + projectDirectoryUrl, + }) + addImportMapForPackage(importsFromPackageField) + if (packagesSelfReference) { const { packageIsRoot, packageDirectoryRelativeUrl } = packageInfo @@ -499,6 +549,22 @@ const packageDependenciesFromPackageObject = (packageObject, { includeDevDepende return packageDependencies } +const moveMappingValue = (address, from, to) => { + const url = resolveUrl(address, from) + const relativeUrl = urlToRelativeUrl(url, to) + if (relativeUrl.startsWith("../")) { + return relativeUrl + } + if (relativeUrl.startsWith("./")) { + return relativeUrl + } + if (/^[a-zA-Z]{2,}:/.test(relativeUrl)) { + // has sheme + return relativeUrl + } + return `./${relativeUrl}` +} + const formatWilcardExportsIgnoredWarning = ({ key, value, packageFileUrl }) => { return `Ignoring export using "*" because it is not supported by importmap. --- key --- diff --git a/src/internal/from-package/visitPackageImportMap.js b/src/internal/from-package/visitPackageImportMap.js new file mode 100644 index 00000000..20c76313 --- /dev/null +++ b/src/internal/from-package/visitPackageImportMap.js @@ -0,0 +1,40 @@ +import { resolveUrl, moveImportMap } from "@jsenv/import-map" +import { readFile, urlToFileSystemPath } from "@jsenv/util" + +export const visitPackageImportMap = async ({ + logger, + packageFileUrl, + packageJsonObject, + packageImportmap = packageJsonObject.importmap, + projectDirectoryUrl, +}) => { + if (typeof packageImportmap === "undefined") { + return {} + } + + if (typeof packageImportmap === "string") { + const importmapFileUrl = resolveUrl(packageImportmap, packageFileUrl) + const importmap = await readFile(importmapFileUrl, { as: "json" }) + return moveImportMap(importmap, importmapFileUrl, projectDirectoryUrl) + } + + if (typeof packageImportmap === "object" && packageImportmap !== null) { + return packageImportmap + } + + logger.warn( + formatUnexpectedPackageImportmapWarning({ + packageImportmap, + packageFileUrl, + }), + ) + return {} +} + +const formatUnexpectedPackageImportmapWarning = ({ packageImportmap, packageFileUrl }) => { + return `unexpected value in package.json importmap field: value must be a string or an object. +--- value --- +${packageImportmap} +--- package.json path --- +${urlToFileSystemPath(packageFileUrl)}` +} diff --git a/test/getImportMapFromProjectFiles/core/shared-indirect/root/node_modules/bar/package.json b/test/getImportMapFromProjectFiles/core/shared-indirect/root/node_modules/bar/package.json index 5feb665f..837a68d9 100644 --- a/test/getImportMapFromProjectFiles/core/shared-indirect/root/node_modules/bar/package.json +++ b/test/getImportMapFromProjectFiles/core/shared-indirect/root/node_modules/bar/package.json @@ -1,7 +1,9 @@ { "module": "bar.js", "dependencies": {}, - "imports": { - "./": "./" + "importmap": { + "imports": { + "./": "./" + } } } diff --git a/test/getImportMapFromProjectFiles/core/symlink/root/node_modules/foo/package.json b/test/getImportMapFromProjectFiles/core/symlink/root/node_modules/foo/package.json index c43e417e..c677d0d6 100644 --- a/test/getImportMapFromProjectFiles/core/symlink/root/node_modules/foo/package.json +++ b/test/getImportMapFromProjectFiles/core/symlink/root/node_modules/foo/package.json @@ -1,6 +1,8 @@ { "module": "index.js", - "imports": { - "./": "./" + "importmap": { + "imports": { + "./": "./" + } } } diff --git a/test/getImportMapFromProjectFiles/package-importmap-field/importmap-scope/importmap-scope.test.js b/test/getImportMapFromProjectFiles/package-importmap-field/importmap-scope/importmap-scope.test.js new file mode 100644 index 00000000..9ce4a76c --- /dev/null +++ b/test/getImportMapFromProjectFiles/package-importmap-field/importmap-scope/importmap-scope.test.js @@ -0,0 +1,21 @@ +import { assert } from "@jsenv/assert" +import { resolveUrl } from "@jsenv/util" +import { getImportMapFromProjectFiles } from "@jsenv/node-module-import-map" + +const testDirectoryUrl = resolveUrl("./root/", import.meta.url) + +const actual = await getImportMapFromProjectFiles({ + projectDirectoryUrl: testDirectoryUrl, + packagesSelfReference: false, +}) +const expected = { + imports: { + foo: "./node_modules/foo/index", + }, + scopes: { + "./node_modules/foo/src/": { + "./a.js": "./node_modules/foo/src/b.js", + }, + }, +} +assert({ actual, expected }) diff --git a/test/getImportMapFromProjectFiles/package-importmap-field/importmap-scope/root/node_modules/foo/package.json b/test/getImportMapFromProjectFiles/package-importmap-field/importmap-scope/root/node_modules/foo/package.json new file mode 100644 index 00000000..5218aa2a --- /dev/null +++ b/test/getImportMapFromProjectFiles/package-importmap-field/importmap-scope/root/node_modules/foo/package.json @@ -0,0 +1,10 @@ +{ + "name": "foo", + "importmap": { + "scopes":{ + "./src/": { + "./a.js": "./src/b.js" + } + } + } +} diff --git a/test/getImportMapFromProjectFiles/package-importmap-field/importmap-scope/root/package.json b/test/getImportMapFromProjectFiles/package-importmap-field/importmap-scope/root/package.json new file mode 100644 index 00000000..399e6ef7 --- /dev/null +++ b/test/getImportMapFromProjectFiles/package-importmap-field/importmap-scope/root/package.json @@ -0,0 +1,6 @@ +{ + "name": "root", + "dependencies": { + "foo": "*" + } +} diff --git a/test/getImportMapFromProjectFiles/package-importmap-field/importmap-top-level/importmap-top-level.test.js b/test/getImportMapFromProjectFiles/package-importmap-field/importmap-top-level/importmap-top-level.test.js new file mode 100644 index 00000000..83d36e36 --- /dev/null +++ b/test/getImportMapFromProjectFiles/package-importmap-field/importmap-top-level/importmap-top-level.test.js @@ -0,0 +1,21 @@ +import { assert } from "@jsenv/assert" +import { resolveUrl } from "@jsenv/util" +import { getImportMapFromProjectFiles } from "@jsenv/node-module-import-map" + +const testDirectoryUrl = resolveUrl("./root/", import.meta.url) + +const actual = await getImportMapFromProjectFiles({ + projectDirectoryUrl: testDirectoryUrl, + packagesSelfReference: false, +}) +const expected = { + imports: { + foo: "./node_modules/foo/index", + }, + scopes: { + "./node_modules/foo/": { + "./a.js": "./node_modules/foo/b.js", + }, + }, +} +assert({ actual, expected }) diff --git a/test/getImportMapFromProjectFiles/package-importmap-field/importmap-top-level/root/node_modules/foo/package.json b/test/getImportMapFromProjectFiles/package-importmap-field/importmap-top-level/root/node_modules/foo/package.json new file mode 100644 index 00000000..39e00836 --- /dev/null +++ b/test/getImportMapFromProjectFiles/package-importmap-field/importmap-top-level/root/node_modules/foo/package.json @@ -0,0 +1,8 @@ +{ + "name": "foo", + "importmap": { + "imports":{ + "./a.js": "./b.js" + } + } +} diff --git a/test/getImportMapFromProjectFiles/package-importmap-field/importmap-top-level/root/package.json b/test/getImportMapFromProjectFiles/package-importmap-field/importmap-top-level/root/package.json new file mode 100644 index 00000000..399e6ef7 --- /dev/null +++ b/test/getImportMapFromProjectFiles/package-importmap-field/importmap-top-level/root/package.json @@ -0,0 +1,6 @@ +{ + "name": "root", + "dependencies": { + "foo": "*" + } +} From 765703d1d634ba4664988f4e9326205473b64ab4 Mon Sep 17 00:00:00 2001 From: Damien Maillard Date: Sun, 7 Mar 2021 20:36:17 +0100 Subject: [PATCH 16/36] update doc --- readme.md | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/readme.md b/readme.md index c3ec5c90..03941a58 100644 --- a/readme.md +++ b/readme.md @@ -287,7 +287,15 @@ await generateImportMapForProject(importMapInputs, { # getImportMapFromProjectFiles -`getImportMapFromProjectFiles` is an async function returning an importMap object computed from infos found in `package.json` files and js files. Your `package.json`, your js files and all the one found in `node_modules` directory are used. +`getImportMapFromProjectFiles` is an async function returning an importMap object computed from infos found in `package.json` files and source files. + +The following source of information are used to create complete and coherent mappings in the importmap. + +- Your `package.json`. +- All your `package.json` `dependencies` are searched into `node_modules`, recursively. +- All file imported by your main entry file (declared in your `package.json`), recursively. + +
getImportMapFromProjectFiles code example From 7b3a8350e00b890447c9565db538e1a1756a6d57 Mon Sep 17 00:00:00 2001 From: Damien Maillard Date: Tue, 9 Mar 2021 11:15:47 +0100 Subject: [PATCH 17/36] Update doc --- readme.md | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/readme.md b/readme.md index 03941a58..e5272e60 100644 --- a/readme.md +++ b/readme.md @@ -224,7 +224,7 @@ However using `*` to add file extension as in } ``` -**is not supported in importmap**. This is tracked in https://github.com/WICG/import-maps/issues/232. +**is not supported in importmap**. Nothing suggests it will be supported for now, read more in https://github.com/WICG/import-maps/issues/232. # generateImportMapForProject @@ -295,8 +295,6 @@ The following source of information are used to create complete and coherent map - All your `package.json` `dependencies` are searched into `node_modules`, recursively. - All file imported by your main entry file (declared in your `package.json`), recursively. - -
getImportMapFromProjectFiles code example From f5d34979085769e41b118e147957cfa2125b08f7 Mon Sep 17 00:00:00 2001 From: Damien Maillard Date: Thu, 11 Mar 2021 11:33:20 +0100 Subject: [PATCH 18/36] prepare testing extensionless --- src/getImportMapFromProjectFiles.js | 44 +++++++------- .../from-js/getImportMapFromJsFiles.js | 60 +++++++++++++------ .../extensionless-js/extensionless-js.test.js | 17 ++++++ .../from-js/extensionless-js/root/file.js | 0 .../from-js/extensionless-js/root/index.js | 2 + .../extensionless-js/root/package.json | 3 + 6 files changed, 84 insertions(+), 42 deletions(-) create mode 100644 test/getImportMapFromProjectFiles/from-js/extensionless-js/extensionless-js.test.js create mode 100644 test/getImportMapFromProjectFiles/from-js/extensionless-js/root/file.js create mode 100644 test/getImportMapFromProjectFiles/from-js/extensionless-js/root/index.js create mode 100644 test/getImportMapFromProjectFiles/from-js/extensionless-js/root/package.json diff --git a/src/getImportMapFromProjectFiles.js b/src/getImportMapFromProjectFiles.js index 3d6b1601..e4aaf7c4 100644 --- a/src/getImportMapFromProjectFiles.js +++ b/src/getImportMapFromProjectFiles.js @@ -1,4 +1,5 @@ -import { sortImportMap } from "@jsenv/import-map" +import { sortImportMap, composeTwoImportMaps } from "@jsenv/import-map" +import { getImportMapFromJsFiles } from "./internal/from-js/getImportMapFromJsFiles.js" import { getImportMapFromPackageFiles } from "./internal/from-package/getImportMapFromPackageFiles.js" export const getImportMapFromProjectFiles = async ({ @@ -6,44 +7,39 @@ export const getImportMapFromProjectFiles = async ({ projectDirectoryUrl, runtime = "browser", dev = false, + magicExtensions, ...rest }) => { + const packagesExportsPreference = [ + "import", + ...(runtimeExportsPreferences[runtime] || [runtime]), + ...(dev ? "development" : "production"), + ] + // At this point, importmap is relative to the project directory url const importMapFromPackageFiles = sortImportMap( await getImportMapFromPackageFiles({ logLevel, projectDirectoryUrl, - packagesExportsPreference: [ - "import", - ...(runtimeExportsPreferences[runtime] || [runtime]), - ...(dev ? "development" : "production"), - ], + packagesExportsPreference, projectPackageDevDependenciesIncluded: dev, ...rest, }), ) - return importMapFromPackageFiles + const importMapFromJsFiles = await getImportMapFromJsFiles({ + logLevel, + importMap: importMapFromPackageFiles, + projectDirectoryUrl, + magicExtensions, + packagesExportsPreference, + runtime, + }) + + return composeTwoImportMaps(importMapFromPackageFiles, importMapFromJsFiles) } const runtimeExportsPreferences = { browser: ["browser"], node: ["node", "require"], } - -// const moveAndSort = (importmap, importMapFileRelativeUrl) => { -// // At this point, importmap is relative to the project directory url -// if (!importMapFileRelativeUrl) { -// return sortImportMap(importmap) -// } - -// // When there is an importMapFileRelativeUrl we will make remapping relative -// // to the importmap file future location (where user will write it). -// // This allows to put the importmap anywhere inside the projectDirectoryUrl. -// // If possible prefer top level because nesting importmap -// // can lead to many relative path like ./file.js -> ../../file.js -// const importMapProjectUrl = resolveUrl("project.importmap", "file://") -// const importMapRealUrl = resolveUrl(importMapFileRelativeUrl, "file://") -// const importmapMoved = moveImportMap(importmap, importMapProjectUrl, importMapRealUrl) -// return sortImportMap(importmapMoved) -// } diff --git a/src/internal/from-js/getImportMapFromJsFiles.js b/src/internal/from-js/getImportMapFromJsFiles.js index 1d1ab797..78d78b0c 100644 --- a/src/internal/from-js/getImportMapFromJsFiles.js +++ b/src/internal/from-js/getImportMapFromJsFiles.js @@ -12,41 +12,65 @@ mais c'est dommage pour chaque bare specifier error (donc pas dans importmap des node_modules) -- s'il existe un fichier avec le meme nom - -> suggerer un remapping et lajouter de force -- si en ajoutant une extension - -> suggerer un remapping et l'ajouter de force - sinon -> suggerer que c'est une dépendance qu'il faut ajouter au package.json non plutot un log de type debug si c'est pas un bare specifier et que le fichier est pas trouvé -- si magic extension - -> suggerer un remapping et l'ajouter de force + -> warning et puis c'est tout */ -import { createDetailedMessage } from "@jsenv/logger" +import { createLogger, createDetailedMessage } from "@jsenv/logger" import { readFile, resolveUrl, urlToExtension } from "@jsenv/util" -// import { resolveImport } from "@jsenv/import-map" +import { resolveImport } from "@jsenv/import-map" import { memoizeAsyncFunctionByUrl } from "../memoizeAsyncFunctionByUrl.js" import { parseSpecifiersFromFile } from "./parseSpecifiersFromFile.js" import { showSource } from "./showSource.js" +const BARE_SPECIFIER_ERROR = {} + export const getImportMapFromJsFiles = async ({ - logger, + logLevel, + importMap, projectDirectoryUrl, magicExtensions = [".js", ".jsx", ".ts", ".tsx", ".node", ".json"], - target, + runtime, packagePreferences, }) => { + const logger = createLogger({ logLevel }) + const visitFile = async (specifier, importer, { importedIn }) => { - const fileUrl = await resolveUrl({ - specifier, - importer, - magicExtensions, - }) + let fileUrl + let bareSpecifier = false + + try { + fileUrl = resolveImport({ + specifier, + importer, + importMap, + defaultExtension: false, + createBareSpecifierError: () => BARE_SPECIFIER_ERROR, + }) + } catch (e) { + if (e !== BARE_SPECIFIER_ERROR) { + throw e + } + bareSpecifier = true + } + + // TODO: auto ajouter importer extension dans les magic extensions + + if (bareSpecifier) { + // - s'il existe un fichier avec le meme nom + // -> suggerer un remapping et lajouter de force + // - si magic extension + // -> suggerer un remapping et l'ajouter de force + } else { + // - si magic extension + // -> suggerer un remapping et l'ajouter de force + } if (!fileUrl) { logger.warn( @@ -87,7 +111,7 @@ export const getImportMapFromJsFiles = async ({ const rootMainInfo = mainFromPackageObject({ packageObject: rootPackageObject, packageFileUrl: rootPackageFileUrl, - target, + runtime, packagePreferences, }) await visitFileMemoized(rootMainInfo.specifier, rootPackageFileUrl, { @@ -95,7 +119,7 @@ export const getImportMapFromJsFiles = async ({ }) } -const mainFromPackageObject = ({ packageObject, packageFileUrl, target }) => { +const mainFromPackageObject = ({ packageObject, packageFileUrl, runtime }) => { // idéalement on lirait aussi package.exports // pour y trouver le point d'entrée principal // soit ".", soit la chaine directe @@ -114,7 +138,7 @@ const mainFromPackageObject = ({ packageObject, packageFileUrl, target }) => { } } - if (target === "browser" && "browser" in packageObject) { + if (runtime === "browser" && "browser" in packageObject) { return { specifier: packageObject.browser, importedIn: `${packageFileUrl}#browser`, diff --git a/test/getImportMapFromProjectFiles/from-js/extensionless-js/extensionless-js.test.js b/test/getImportMapFromProjectFiles/from-js/extensionless-js/extensionless-js.test.js new file mode 100644 index 00000000..588a3f78 --- /dev/null +++ b/test/getImportMapFromProjectFiles/from-js/extensionless-js/extensionless-js.test.js @@ -0,0 +1,17 @@ +import { assert } from "@jsenv/assert" +import { resolveUrl } from "@jsenv/util" +import { getImportMapFromProjectFiles } from "@jsenv/node-module-import-map" + +const testDirectoryUrl = resolveUrl("./root/", import.meta.url) + +const actual = await getImportMapFromProjectFiles({ + projectDirectoryUrl: testDirectoryUrl, +}) +const expected = { + imports: { + "root/": "./", + "root": "./index.js", + }, + scopes: {}, +} +assert({ actual, expected }) diff --git a/test/getImportMapFromProjectFiles/from-js/extensionless-js/root/file.js b/test/getImportMapFromProjectFiles/from-js/extensionless-js/root/file.js new file mode 100644 index 00000000..e69de29b diff --git a/test/getImportMapFromProjectFiles/from-js/extensionless-js/root/index.js b/test/getImportMapFromProjectFiles/from-js/extensionless-js/root/index.js new file mode 100644 index 00000000..6bbcd8a0 --- /dev/null +++ b/test/getImportMapFromProjectFiles/from-js/extensionless-js/root/index.js @@ -0,0 +1,2 @@ +// eslint-disable-next-line import/no-unresolved +import "./file" diff --git a/test/getImportMapFromProjectFiles/from-js/extensionless-js/root/package.json b/test/getImportMapFromProjectFiles/from-js/extensionless-js/root/package.json new file mode 100644 index 00000000..7636edf1 --- /dev/null +++ b/test/getImportMapFromProjectFiles/from-js/extensionless-js/root/package.json @@ -0,0 +1,3 @@ +{ + "name": "root" +} From c3a5ccdf14a69ada43becf32a7481fcf731983df Mon Sep 17 00:00:00 2001 From: Damien Maillard Date: Thu, 11 Mar 2021 14:28:29 +0100 Subject: [PATCH 19/36] Remove undocumented packagesSelfReference It's now officially documented and supported by Node.js --- src/getImportMapFromProjectFiles.js | 41 ++++++---- .../from-js/parseSpecifiersFromFile.js | 8 +- .../getImportMapFromPackageFiles.js | 82 +++++++------------ .../core/basic/basic.test.js | 11 +-- .../root/node_modules/@dmail/yo/package.json | 5 +- .../basic/root/node_modules/bar/package.json | 5 +- .../foo/node_modules/bar/package.json | 5 +- .../basic/root/node_modules/foo/package.json | 3 + .../core/basic/root/package.json | 3 + .../core/circular/circular.test.js | 3 +- .../core/inside/inside.test.js | 3 +- .../core/issue-20/issue-20.test.js | 11 +-- .../malformed-dependency-package.test.js | 6 +- .../missing-dependency-package.test.js | 6 +- .../missing-root-package.test.js | 2 +- .../optional-dependency.test.js | 6 +- .../scoped-inside-scoped.test.js | 5 +- .../shared-indirect/shared-indirect.test.js | 8 +- .../core/shared/shared.test.js | 7 +- .../nested/node_modules/bar/package.json | 5 +- .../nested/node_modules/foo/package.json | 3 + .../root/node_modules/nested/package.json | 6 +- .../core/sibling-and-deep/root/package.json | 4 +- .../sibling-and-deep/sibling-and-deep.test.js | 5 +- .../root/node_modules/foo/package.json | 1 + .../project/node_modules/foo/package.json | 3 - .../core/symlink/root/project/package.json | 6 -- .../core/symlink/symlink.test.js | 5 +- .../extensionless-js/extensionless-js.test.js | 3 +- .../included-predicate.test.js | 2 +- .../manual-override/manual-override.test.js | 5 +- .../{ => root}/node_modules/bar/bar.js | 0 .../{ => root}/node_modules/bar/package.json | 0 .../manual-override/{ => root}/package.json | 0 .../exports-and-main/exports-and-main.test.js | 3 +- .../exports-complex/exports-complex.test.js | 21 +++-- .../{ => root}/node_modules/foo/file.cjs | 0 .../{ => root}/node_modules/foo/package.json | 0 .../exports-complex/{ => root}/package.json | 0 .../exports-condition-nested.test.js | 6 +- .../exports-directory-scoped.test.js | 3 +- .../exports-directory.test.js | 5 +- .../node_modules/@jsenv/whatever}/index.js | 0 .../node_modules/@jsenv/whatever/package.json | 0 .../exports-directory/{ => root}/package.json | 0 .../exports-file-conditional.test.js | 12 +-- .../{ => root}/node_modules/foo/package.json | 0 .../{ => root}/package.json | 0 .../exports-file-deep-2.test.js | 5 +- .../foo/node_modules/bar/package.json | 0 .../{ => root}/node_modules/foo/package.json | 0 .../{ => root}/package.json | 0 .../exports-file-deep.test.js | 5 +- .../{ => root}/node_modules/bar/package.json | 0 .../{ => root}/node_modules/foo/package.json | 0 .../exports-file-deep/{ => root}/package.json | 0 .../exports-file/exports-file.test.js | 5 +- .../root}/node_modules/foo/index.js | 0 .../{ => root}/node_modules/foo/package.json | 0 .../exports-file/{ => root}/package.json | 0 .../exports-pattern-directory.test.js | 4 +- .../{ => root}/node_modules/foo/package.json | 0 .../{ => root}/package.json | 0 .../exports-pattern-extensionless.test.js | 4 +- .../{ => root}/node_modules/foo/package.json | 0 .../{ => root}/package.json | 0 .../exports-string/exports-string.test.js | 5 +- .../{ => root}/node_modules/foo/package.json | 0 .../exports-string/{ => root}/package.json | 0 .../exports-sugar-conditional.test.js | 10 +-- .../{ => root}/node_modules/foo/package.json | 0 .../{ => root}/package.json | 0 .../exports-sugar/exports-sugar.test.js | 5 +- .../{ => root}/node_modules/foo/package.json | 0 .../exports-sugar/{ => root}/package.json | 0 .../importmap-scope/importmap-scope.test.js | 3 +- .../importmap-top-level.test.js | 3 +- .../main-directory-trailing.test.js | 5 +- .../main-folder-trailing/lib}/index.js | 0 .../main-folder-trailing/package.json | 0 .../{ => root}/package.json | 0 .../main-directory/main-directory.test.js | 4 +- .../node_modules/main-directory/lib}/index.js | 0 .../node_modules/main-directory/package.json | 0 .../main-directory/{ => root}/package.json | 0 .../main-jsnext/main-jsnext.test.js | 5 +- .../node_modules/main-jsnext/jsnext.js | 0 .../node_modules/main-jsnext/package.json | 0 .../main-jsnext/{ => root}/package.json | 0 .../main-relative/main-relative.test.js | 5 +- .../node_modules/main-relative}/lib/index.js | 0 .../node_modules/main-relative/package.json | 0 .../main-relative/{ => root}/package.json | 0 .../main-undefined/main-undefined.test.js | 5 +- .../node_modules/main-undefined}/index.js | 0 .../node_modules/main-undefined/package.json | 0 .../main-undefined/{ => root}/package.json | 0 .../main-without-extension.test.js | 3 +- .../self-import-1/self-import.test.js | 3 +- .../self-import-2/node_modules/foo/index.js | 0 .../node_modules/foo/package.json | 3 - .../self-import-2/root}/index.js | 0 .../root/node_modules/foo}/index.js | 0 .../root/node_modules/foo/package.json | 6 ++ .../self-import-2/{ => root}/package.json | 0 .../self-import-2/self-import-2.test.js | 10 +-- .../self-import/self-import-4/index.js | 0 .../node_modules/@jsenv/core/package.json | 3 - .../root}/index.js | 0 .../node_modules/@jsenv/core/package.json | 0 .../self-import-4/{ => root}/package.json | 3 + .../self-import-4/self-import-4.test.js | 4 +- .../node_modules/@jsenv/core/package.json | 6 ++ .../self-import-5/{ => root}/package.json | 3 + .../self-import-5/self-import-5.test.js | 4 +- .../self-import-6/self-import-6.test.js | 2 - 116 files changed, 238 insertions(+), 203 deletions(-) delete mode 100644 test/getImportMapFromProjectFiles/core/symlink/root/project/node_modules/foo/package.json delete mode 100644 test/getImportMapFromProjectFiles/core/symlink/root/project/package.json rename test/getImportMapFromProjectFiles/manual-override/{ => root}/node_modules/bar/bar.js (100%) rename test/getImportMapFromProjectFiles/manual-override/{ => root}/node_modules/bar/package.json (100%) rename test/getImportMapFromProjectFiles/manual-override/{ => root}/package.json (100%) rename test/getImportMapFromProjectFiles/package-exports-field/exports-complex/{ => root}/node_modules/foo/file.cjs (100%) rename test/getImportMapFromProjectFiles/package-exports-field/exports-complex/{ => root}/node_modules/foo/package.json (100%) rename test/getImportMapFromProjectFiles/package-exports-field/exports-complex/{ => root}/package.json (100%) rename test/getImportMapFromProjectFiles/{core/symlink/root/project => package-exports-field/exports-directory/root/node_modules/@jsenv/whatever}/index.js (100%) rename test/getImportMapFromProjectFiles/package-exports-field/exports-directory/{ => root}/node_modules/@jsenv/whatever/package.json (100%) rename test/getImportMapFromProjectFiles/package-exports-field/exports-directory/{ => root}/package.json (100%) rename test/getImportMapFromProjectFiles/package-exports-field/exports-file-conditional/{ => root}/node_modules/foo/package.json (100%) rename test/getImportMapFromProjectFiles/package-exports-field/exports-file-conditional/{ => root}/package.json (100%) rename test/getImportMapFromProjectFiles/package-exports-field/exports-file-deep-2/{ => root}/node_modules/foo/node_modules/bar/package.json (100%) rename test/getImportMapFromProjectFiles/package-exports-field/exports-file-deep-2/{ => root}/node_modules/foo/package.json (100%) rename test/getImportMapFromProjectFiles/package-exports-field/exports-file-deep-2/{ => root}/package.json (100%) rename test/getImportMapFromProjectFiles/package-exports-field/exports-file-deep/{ => root}/node_modules/bar/package.json (100%) rename test/getImportMapFromProjectFiles/package-exports-field/exports-file-deep/{ => root}/node_modules/foo/package.json (100%) rename test/getImportMapFromProjectFiles/package-exports-field/exports-file-deep/{ => root}/package.json (100%) rename test/getImportMapFromProjectFiles/{core/symlink/root/project => package-exports-field/exports-file/root}/node_modules/foo/index.js (100%) rename test/getImportMapFromProjectFiles/package-exports-field/exports-file/{ => root}/node_modules/foo/package.json (100%) rename test/getImportMapFromProjectFiles/package-exports-field/exports-file/{ => root}/package.json (100%) rename test/getImportMapFromProjectFiles/package-exports-field/exports-pattern-directory/{ => root}/node_modules/foo/package.json (100%) rename test/getImportMapFromProjectFiles/package-exports-field/exports-pattern-directory/{ => root}/package.json (100%) rename test/getImportMapFromProjectFiles/package-exports-field/exports-pattern-extensionless/{ => root}/node_modules/foo/package.json (100%) rename test/getImportMapFromProjectFiles/package-exports-field/exports-pattern-extensionless/{ => root}/package.json (100%) rename test/getImportMapFromProjectFiles/package-exports-field/exports-string/{ => root}/node_modules/foo/package.json (100%) rename test/getImportMapFromProjectFiles/package-exports-field/exports-string/{ => root}/package.json (100%) rename test/getImportMapFromProjectFiles/package-exports-field/exports-sugar-conditional/{ => root}/node_modules/foo/package.json (100%) rename test/getImportMapFromProjectFiles/package-exports-field/exports-sugar-conditional/{ => root}/package.json (100%) rename test/getImportMapFromProjectFiles/package-exports-field/exports-sugar/{ => root}/node_modules/foo/package.json (100%) rename test/getImportMapFromProjectFiles/package-exports-field/exports-sugar/{ => root}/package.json (100%) rename test/getImportMapFromProjectFiles/{package-exports-field/exports-directory/node_modules/@jsenv/whatever => package-main-field/main-directory-trailing/root/node_modules/main-folder-trailing/lib}/index.js (100%) rename test/getImportMapFromProjectFiles/package-main-field/main-directory-trailing/{ => root}/node_modules/main-folder-trailing/package.json (100%) rename test/getImportMapFromProjectFiles/package-main-field/main-directory-trailing/{ => root}/package.json (100%) rename test/getImportMapFromProjectFiles/{package-exports-field/exports-file/node_modules/foo => package-main-field/main-directory/root/node_modules/main-directory/lib}/index.js (100%) rename test/getImportMapFromProjectFiles/package-main-field/main-directory/{ => root}/node_modules/main-directory/package.json (100%) rename test/getImportMapFromProjectFiles/package-main-field/main-directory/{ => root}/package.json (100%) rename test/getImportMapFromProjectFiles/package-main-field/main-jsnext/{ => root}/node_modules/main-jsnext/jsnext.js (100%) rename test/getImportMapFromProjectFiles/package-main-field/main-jsnext/{ => root}/node_modules/main-jsnext/package.json (100%) rename test/getImportMapFromProjectFiles/package-main-field/main-jsnext/{ => root}/package.json (100%) rename test/getImportMapFromProjectFiles/package-main-field/{main-directory-trailing/node_modules/main-folder-trailing => main-relative/root/node_modules/main-relative}/lib/index.js (100%) rename test/getImportMapFromProjectFiles/package-main-field/main-relative/{ => root}/node_modules/main-relative/package.json (100%) rename test/getImportMapFromProjectFiles/package-main-field/main-relative/{ => root}/package.json (100%) rename test/getImportMapFromProjectFiles/package-main-field/{main-directory/node_modules/main-directory/lib => main-undefined/root/node_modules/main-undefined}/index.js (100%) rename test/getImportMapFromProjectFiles/package-main-field/main-undefined/{ => root}/node_modules/main-undefined/package.json (100%) rename test/getImportMapFromProjectFiles/package-main-field/main-undefined/{ => root}/package.json (100%) delete mode 100644 test/getImportMapFromProjectFiles/self-import/self-import-2/node_modules/foo/index.js delete mode 100644 test/getImportMapFromProjectFiles/self-import/self-import-2/node_modules/foo/package.json rename test/getImportMapFromProjectFiles/{package-main-field/main-relative/node_modules/main-relative/lib => self-import/self-import-2/root}/index.js (100%) rename test/getImportMapFromProjectFiles/{package-main-field/main-undefined/node_modules/main-undefined => self-import/self-import-2/root/node_modules/foo}/index.js (100%) create mode 100644 test/getImportMapFromProjectFiles/self-import/self-import-2/root/node_modules/foo/package.json rename test/getImportMapFromProjectFiles/self-import/self-import-2/{ => root}/package.json (100%) delete mode 100644 test/getImportMapFromProjectFiles/self-import/self-import-4/index.js delete mode 100644 test/getImportMapFromProjectFiles/self-import/self-import-4/node_modules/@jsenv/core/package.json rename test/getImportMapFromProjectFiles/self-import/{self-import-2 => self-import-4/root}/index.js (100%) rename test/getImportMapFromProjectFiles/self-import/{self-import-5 => self-import-4/root}/node_modules/@jsenv/core/package.json (100%) rename test/getImportMapFromProjectFiles/self-import/self-import-4/{ => root}/package.json (73%) create mode 100644 test/getImportMapFromProjectFiles/self-import/self-import-5/root/node_modules/@jsenv/core/package.json rename test/getImportMapFromProjectFiles/self-import/self-import-5/{ => root}/package.json (73%) diff --git a/src/getImportMapFromProjectFiles.js b/src/getImportMapFromProjectFiles.js index e4aaf7c4..59e81d10 100644 --- a/src/getImportMapFromProjectFiles.js +++ b/src/getImportMapFromProjectFiles.js @@ -6,40 +6,49 @@ export const getImportMapFromProjectFiles = async ({ logLevel, projectDirectoryUrl, runtime = "browser", + moduleFormat = "esm", dev = false, + jsFiles = false, magicExtensions, ...rest }) => { const packagesExportsPreference = [ - "import", + ...(moduleFormatPreferences[moduleFormat] || [moduleFormat]), ...(runtimeExportsPreferences[runtime] || [runtime]), ...(dev ? "development" : "production"), ] // At this point, importmap is relative to the project directory url - const importMapFromPackageFiles = sortImportMap( - await getImportMapFromPackageFiles({ - logLevel, - projectDirectoryUrl, - packagesExportsPreference, - projectPackageDevDependenciesIncluded: dev, - ...rest, - }), - ) - - const importMapFromJsFiles = await getImportMapFromJsFiles({ + let importMapFromPackageFiles = await getImportMapFromPackageFiles({ logLevel, - importMap: importMapFromPackageFiles, projectDirectoryUrl, - magicExtensions, packagesExportsPreference, - runtime, + projectPackageDevDependenciesIncluded: dev, + ...rest, }) + importMapFromPackageFiles = sortImportMap(importMapFromPackageFiles) + + let importMapFromJsFiles = jsFiles + ? await getImportMapFromJsFiles({ + logLevel, + importMap: importMapFromPackageFiles, + projectDirectoryUrl, + magicExtensions, + packagesExportsPreference, + runtime, + }) + : {} + importMapFromJsFiles = sortImportMap(importMapFromJsFiles) return composeTwoImportMaps(importMapFromPackageFiles, importMapFromJsFiles) } const runtimeExportsPreferences = { browser: ["browser"], - node: ["node", "require"], + node: ["node"], +} + +const moduleFormatPreferences = { + esm: ["import"], + cjs: ["require"], } diff --git a/src/internal/from-js/parseSpecifiersFromFile.js b/src/internal/from-js/parseSpecifiersFromFile.js index 140abadb..c001e2b9 100644 --- a/src/internal/from-js/parseSpecifiersFromFile.js +++ b/src/internal/from-js/parseSpecifiersFromFile.js @@ -1,7 +1,11 @@ -import parser from "@babel/parser" -import traverse from "@babel/traverse" +import { createRequire } from "module" import { readFile, urlToFileSystemPath } from "@jsenv/util" +const require = createRequire(import.meta.url) + +const parser = require("@babel/parser") +const traverse = require("@babel/traverse") + export const parseSpecifiersFromFile = async ( fileUrl, { diff --git a/src/internal/from-package/getImportMapFromPackageFiles.js b/src/internal/from-package/getImportMapFromPackageFiles.js index 921dbcab..3c65b857 100644 --- a/src/internal/from-package/getImportMapFromPackageFiles.js +++ b/src/internal/from-package/getImportMapFromPackageFiles.js @@ -22,7 +22,6 @@ export const getImportMapFromPackageFiles = async ({ projectPackageDevDependenciesIncluded = process.env.NODE_ENV !== "production", packagesExportsPreference = ["import", "browser"], packagesExportsIncluded = true, - packagesSelfReference = true, packagesManualOverrides = {}, packageIncludedPredicate = () => true, }) => { @@ -65,6 +64,12 @@ export const getImportMapFromPackageFiles = async ({ from: scope, to: scope, }) + const packageName = scope.slice(scope.lastIndexOf("node_modules/") + `node_modules/`.length) + addScopedImportMapping({ + scope, + from: packageName, + to: scope, + }) } scopes[scope] = { @@ -116,7 +121,6 @@ export const getImportMapFromPackageFiles = async ({ packageName, packageJsonObject, importerPackageFileUrl, - importerPackageJsonObject, }) => { const packageInfo = computePackageInfo({ packageFileUrl, @@ -190,11 +194,6 @@ export const getImportMapFromPackageFiles = async ({ const addMappingsForPackageAndImporter = (mappings) => { if (packageIsRoot) { - if (!packagesSelfReference) { - // ignore exports - return - } - Object.keys(mappings).forEach((from) => { const to = mappings[from] addTopLevelImportMapping({ @@ -209,20 +208,12 @@ export const getImportMapFromPackageFiles = async ({ // own package mappings available to himself Object.keys(mappings).forEach((from) => { const to = mappings[from] - // importer is the package himself, keep exports scoped - // otherwise the dependency mappings would override the importer mappings. - if (importerPackageJsonObject.name === packageName) { - addScopedImportMapping({ - scope: `./${packageDirectoryRelativeUrl}`, - from, - to, - }) - if (from === packageName || from in imports === false) { - addTopLevelImportMapping({ from, to }) - } - } else { - addTopLevelImportMapping({ from, to }) - } + addScopedImportMapping({ + scope: `./${packageDirectoryRelativeUrl}`, + from, + to, + }) + addTopLevelImportMapping({ from, to }) }) // if importer is root no need to make package mappings available to the importer @@ -232,7 +223,6 @@ export const getImportMapFromPackageFiles = async ({ Object.keys(mappings).forEach((from) => { const to = mappings[from] - // own package exports available to himself addScopedImportMapping({ scope: `./${packageDirectoryRelativeUrl}`, @@ -242,7 +232,11 @@ export const getImportMapFromPackageFiles = async ({ // now make package exports available to the importer // here if the importer is himself we could do stuff // we should even handle the case earlier to prevent top level remapping - addScopedImportMapping({ scope: `./${importerRelativeUrl}`, from, to }) + addScopedImportMapping({ + scope: `./${importerRelativeUrl}`, + from, + to, + }) }) } @@ -254,26 +248,6 @@ export const getImportMapFromPackageFiles = async ({ }) addImportMapForPackage(importsFromPackageField) - if (packagesSelfReference) { - const { packageIsRoot, packageDirectoryRelativeUrl } = packageInfo - - // allow import 'package-name/dir/file.js' in package-name files - if (packageIsRoot) { - addTopLevelImportMapping({ - from: `${packageName}/`, - to: `./${packageDirectoryRelativeUrl}`, - }) - } - // scoped allow import 'package-name/dir/file.js' in package-name files - else { - addScopedImportMapping({ - scope: `./${packageDirectoryRelativeUrl}`, - from: `${packageName}/`, - to: `./${packageDirectoryRelativeUrl}`, - }) - } - } - if (packagesExportsIncluded && "exports" in packageJsonObject) { const mappingsFromPackageExports = {} visitPackageExports({ @@ -328,16 +302,10 @@ export const getImportMapFromPackageFiles = async ({ packageInfo: { importerIsRoot, importerRelativeUrl, - packageIsRoot, packageDirectoryUrl, packageDirectoryUrlExpected, }, }) => { - const self = packageIsRoot - if (self && !packagesSelfReference) { - return - } - const mainFileUrl = await resolvePackageMain({ packageFileUrl, packageJsonObject, @@ -347,7 +315,9 @@ export const getImportMapFromPackageFiles = async ({ // it's possible to have no main // like { main: "" } in package.json // or a main that does not lead to an actual file - if (mainFileUrl === null) return + if (mainFileUrl === null) { + return + } const mainFileRelativeUrl = urlToRelativeUrl(mainFileUrl, projectDirectoryUrl) const from = packageName @@ -356,10 +326,18 @@ export const getImportMapFromPackageFiles = async ({ if (importerIsRoot) { addTopLevelImportMapping({ from, to }) } else { - addScopedImportMapping({ scope: `./${importerRelativeUrl}`, from, to }) + addScopedImportMapping({ + scope: `./${importerRelativeUrl}`, + from, + to, + }) } if (packageDirectoryUrl !== packageDirectoryUrlExpected) { - addScopedImportMapping({ scope: `./${importerRelativeUrl}`, from, to }) + addScopedImportMapping({ + scope: `./${importerRelativeUrl}`, + from, + to, + }) } } diff --git a/test/getImportMapFromProjectFiles/core/basic/basic.test.js b/test/getImportMapFromProjectFiles/core/basic/basic.test.js index 55592d76..d25af855 100644 --- a/test/getImportMapFromProjectFiles/core/basic/basic.test.js +++ b/test/getImportMapFromProjectFiles/core/basic/basic.test.js @@ -9,8 +9,11 @@ const actual = await getImportMapFromProjectFiles({ }) const expected = { imports: { + "@dmail/yo/": "./node_modules/@dmail/yo/", "@dmail/yo": "./node_modules/@dmail/yo/index.js", "root/": "./", + "bar/": "./node_modules/bar/", + "foo/": "./node_modules/foo/", "root": "./index.js", "bar": "./node_modules/bar/bar.js", "foo": "./node_modules/foo/foo.js", @@ -19,14 +22,8 @@ const expected = { "./node_modules/foo/node_modules/bar/": { "bar/": "./node_modules/foo/node_modules/bar/", }, - "./node_modules/@dmail/yo/": { - "@dmail/yo/": "./node_modules/@dmail/yo/", - }, - "./node_modules/bar/": { - "bar/": "./node_modules/bar/", - }, "./node_modules/foo/": { - "foo/": "./node_modules/foo/", + "bar/": "./node_modules/foo/node_modules/bar/", "bar": "./node_modules/foo/node_modules/bar/index.js", }, }, diff --git a/test/getImportMapFromProjectFiles/core/basic/root/node_modules/@dmail/yo/package.json b/test/getImportMapFromProjectFiles/core/basic/root/node_modules/@dmail/yo/package.json index 5a628b5b..fac4362f 100644 --- a/test/getImportMapFromProjectFiles/core/basic/root/node_modules/@dmail/yo/package.json +++ b/test/getImportMapFromProjectFiles/core/basic/root/node_modules/@dmail/yo/package.json @@ -1,3 +1,6 @@ { - "module": "index.js" + "module": "index.js", + "exports": { + "./": "./" + } } \ No newline at end of file diff --git a/test/getImportMapFromProjectFiles/core/basic/root/node_modules/bar/package.json b/test/getImportMapFromProjectFiles/core/basic/root/node_modules/bar/package.json index 3ca9992c..381d399e 100644 --- a/test/getImportMapFromProjectFiles/core/basic/root/node_modules/bar/package.json +++ b/test/getImportMapFromProjectFiles/core/basic/root/node_modules/bar/package.json @@ -1,4 +1,7 @@ { "module": "bar.js", - "dependencies": {} + "dependencies": {}, + "exports": { + "./": "./" + } } diff --git a/test/getImportMapFromProjectFiles/core/basic/root/node_modules/foo/node_modules/bar/package.json b/test/getImportMapFromProjectFiles/core/basic/root/node_modules/foo/node_modules/bar/package.json index 6cbb3669..b6d0d602 100644 --- a/test/getImportMapFromProjectFiles/core/basic/root/node_modules/foo/node_modules/bar/package.json +++ b/test/getImportMapFromProjectFiles/core/basic/root/node_modules/foo/node_modules/bar/package.json @@ -1,3 +1,6 @@ { - "module": "index.js" + "module": "index.js", + "exports": { + "./": "./" + } } diff --git a/test/getImportMapFromProjectFiles/core/basic/root/node_modules/foo/package.json b/test/getImportMapFromProjectFiles/core/basic/root/node_modules/foo/package.json index be1eef68..278e5268 100644 --- a/test/getImportMapFromProjectFiles/core/basic/root/node_modules/foo/package.json +++ b/test/getImportMapFromProjectFiles/core/basic/root/node_modules/foo/package.json @@ -2,5 +2,8 @@ "module": "foo.js", "dependencies": { "bar": "*" + }, + "exports": { + "./": "./" } } diff --git a/test/getImportMapFromProjectFiles/core/basic/root/package.json b/test/getImportMapFromProjectFiles/core/basic/root/package.json index 28b6d12f..bd22c43f 100644 --- a/test/getImportMapFromProjectFiles/core/basic/root/package.json +++ b/test/getImportMapFromProjectFiles/core/basic/root/package.json @@ -6,5 +6,8 @@ "bar": "*", "foo": "*", "@dmail/yo": "*" + }, + "exports": { + "./": "./" } } diff --git a/test/getImportMapFromProjectFiles/core/circular/circular.test.js b/test/getImportMapFromProjectFiles/core/circular/circular.test.js index ccf4aeed..45056061 100644 --- a/test/getImportMapFromProjectFiles/core/circular/circular.test.js +++ b/test/getImportMapFromProjectFiles/core/circular/circular.test.js @@ -6,10 +6,11 @@ const testDirectoryUrl = resolveUrl("./root/", import.meta.url) const actual = await getImportMapFromProjectFiles({ projectDirectoryUrl: testDirectoryUrl, - packagesSelfReference: false, + jsFiles: false, }) const expected = { imports: { + whatever: "./index", bar: "./node_modules/bar/bar.js", foo: "./node_modules/foo/foo.js", }, diff --git a/test/getImportMapFromProjectFiles/core/inside/inside.test.js b/test/getImportMapFromProjectFiles/core/inside/inside.test.js index 5647c411..a6c60cb7 100644 --- a/test/getImportMapFromProjectFiles/core/inside/inside.test.js +++ b/test/getImportMapFromProjectFiles/core/inside/inside.test.js @@ -7,11 +7,12 @@ const testDirectoryUrl = resolveUrl("./root/", import.meta.url) const importMap = await getImportMapFromProjectFiles({ projectDirectoryUrl: testDirectoryUrl, - packagesSelfReference: false, + jsFiles: false, }) const actual = importMap const expected = { imports: { + root: "./index", bar: "./node_modules/bar/bar.js", foo: "./node_modules/foo/foo.js", }, diff --git a/test/getImportMapFromProjectFiles/core/issue-20/issue-20.test.js b/test/getImportMapFromProjectFiles/core/issue-20/issue-20.test.js index 2ff0f8a7..212fa02c 100644 --- a/test/getImportMapFromProjectFiles/core/issue-20/issue-20.test.js +++ b/test/getImportMapFromProjectFiles/core/issue-20/issue-20.test.js @@ -12,17 +12,12 @@ const importMap = await getImportMapFromProjectFiles({ const actual = importMap const expected = { imports: { - "root/": "./", - "lume": "./node_modules/lume/lume.js", - "root": "./index", + lume: "./node_modules/lume/lume.js", + root: "./index", }, scopes: { - "./node_modules/lume/node_modules/lowclass/": { - "lowclass/": "./node_modules/lume/node_modules/lowclass/", - }, "./node_modules/lume/": { - "lowclass": "./node_modules/lume/node_modules/lowclass/dist/index.js", - "lume/": "./node_modules/lume/", + lowclass: "./node_modules/lume/node_modules/lowclass/dist/index.js", }, }, } diff --git a/test/getImportMapFromProjectFiles/core/malformed-dependency-package/malformed-dependency-package.test.js b/test/getImportMapFromProjectFiles/core/malformed-dependency-package/malformed-dependency-package.test.js index 0306ea3b..881e1d5a 100644 --- a/test/getImportMapFromProjectFiles/core/malformed-dependency-package/malformed-dependency-package.test.js +++ b/test/getImportMapFromProjectFiles/core/malformed-dependency-package/malformed-dependency-package.test.js @@ -7,10 +7,12 @@ const testDirectoryUrl = resolveUrl("./root/", import.meta.url) const actual = await getImportMapFromProjectFiles({ logLevel: "off", projectDirectoryUrl: testDirectoryUrl, - packagesSelfReference: false, + jsFiles: false, }) const expected = { - imports: {}, + imports: { + root: "./index", + }, scopes: {}, } // we could/should also expect a console.warn occurs diff --git a/test/getImportMapFromProjectFiles/core/missing-dependency-package/missing-dependency-package.test.js b/test/getImportMapFromProjectFiles/core/missing-dependency-package/missing-dependency-package.test.js index 7177d459..013453ae 100644 --- a/test/getImportMapFromProjectFiles/core/missing-dependency-package/missing-dependency-package.test.js +++ b/test/getImportMapFromProjectFiles/core/missing-dependency-package/missing-dependency-package.test.js @@ -7,10 +7,12 @@ const testDirectoryUrl = resolveUrl("./root/", import.meta.url) const actual = await getImportMapFromProjectFiles({ logLevel: "error", projectDirectoryUrl: testDirectoryUrl, - packagesSelfReference: false, + jsFiles: false, }) const expected = { - imports: {}, + imports: { + root: "./index", + }, scopes: {}, } assert({ actual, expected }) diff --git a/test/getImportMapFromProjectFiles/core/missing-root-package/missing-root-package.test.js b/test/getImportMapFromProjectFiles/core/missing-root-package/missing-root-package.test.js index 69c0336b..42ece12c 100644 --- a/test/getImportMapFromProjectFiles/core/missing-root-package/missing-root-package.test.js +++ b/test/getImportMapFromProjectFiles/core/missing-root-package/missing-root-package.test.js @@ -8,7 +8,7 @@ const packageFileUrl = resolveUrl("./package.json", testDirectoryUrl) try { await getImportMapFromProjectFiles({ projectDirectoryUrl: testDirectoryUrl, - packagesSelfReference: false, + jsFiles: false, }) throw new Error("should throw") } catch (error) { diff --git a/test/getImportMapFromProjectFiles/core/optional-dependency/optional-dependency.test.js b/test/getImportMapFromProjectFiles/core/optional-dependency/optional-dependency.test.js index 78599d97..ec2b0762 100644 --- a/test/getImportMapFromProjectFiles/core/optional-dependency/optional-dependency.test.js +++ b/test/getImportMapFromProjectFiles/core/optional-dependency/optional-dependency.test.js @@ -6,10 +6,12 @@ const testDirectoryUrl = resolveUrl("./root/", import.meta.url) const actual = await getImportMapFromProjectFiles({ projectDirectoryUrl: testDirectoryUrl, - packagesSelfReference: false, + jsFiles: false, }) const expected = { - imports: {}, + imports: { + root: "./index.js", + }, scopes: {}, } assert({ actual, expected }) diff --git a/test/getImportMapFromProjectFiles/core/scoped-inside-scoped/scoped-inside-scoped.test.js b/test/getImportMapFromProjectFiles/core/scoped-inside-scoped/scoped-inside-scoped.test.js index b5818287..88410219 100644 --- a/test/getImportMapFromProjectFiles/core/scoped-inside-scoped/scoped-inside-scoped.test.js +++ b/test/getImportMapFromProjectFiles/core/scoped-inside-scoped/scoped-inside-scoped.test.js @@ -6,12 +6,13 @@ const testDirectoryUrl = resolveUrl("./root/", import.meta.url) const actual = await getImportMapFromProjectFiles({ projectDirectoryUrl: testDirectoryUrl, - projectPackageDevDependenciesIncluded: true, - packagesSelfReference: false, + dev: true, + jsFiles: false, }) const expected = { imports: { "@jsenv/bundling": "./node_modules/@jsenv/bundling/whatever.js", + "root": "./index", }, scopes: { "./node_modules/@jsenv/bundling/node_modules/@jsenv/core/": { diff --git a/test/getImportMapFromProjectFiles/core/shared-indirect/shared-indirect.test.js b/test/getImportMapFromProjectFiles/core/shared-indirect/shared-indirect.test.js index 1c01c584..2b5e279d 100644 --- a/test/getImportMapFromProjectFiles/core/shared-indirect/shared-indirect.test.js +++ b/test/getImportMapFromProjectFiles/core/shared-indirect/shared-indirect.test.js @@ -12,9 +12,8 @@ const importMap = await getImportMapFromProjectFiles({ const actual = importMap const expected = { imports: { - "root/": "./", - "root": "./index", - "foo": "./node_modules/foo/foo.js", + root: "./index", + foo: "./node_modules/foo/foo.js", }, scopes: { "./node_modules/bar/": { @@ -23,8 +22,7 @@ const importMap = await getImportMapFromProjectFiles({ "./": "./node_modules/bar/", }, "./node_modules/foo/": { - "foo/": "./node_modules/foo/", - "bar": "./node_modules/bar/bar.js", + bar: "./node_modules/bar/bar.js", }, }, } diff --git a/test/getImportMapFromProjectFiles/core/shared/shared.test.js b/test/getImportMapFromProjectFiles/core/shared/shared.test.js index 6385b336..9777d827 100644 --- a/test/getImportMapFromProjectFiles/core/shared/shared.test.js +++ b/test/getImportMapFromProjectFiles/core/shared/shared.test.js @@ -12,17 +12,12 @@ const importMap = await getImportMapFromProjectFiles({ const actual = importMap const expected = { imports: { - "root/": "./", "bar/": "./node_modules/bar/", "root": "./index", "bar": "./node_modules/bar/bar.js", "foo": "./node_modules/foo/foo.js", }, - scopes: { - "./node_modules/foo/": { - "foo/": "./node_modules/foo/", - }, - }, + scopes: {}, } assert({ actual, expected }) } diff --git a/test/getImportMapFromProjectFiles/core/sibling-and-deep/root/node_modules/nested/node_modules/bar/package.json b/test/getImportMapFromProjectFiles/core/sibling-and-deep/root/node_modules/nested/node_modules/bar/package.json index 3ca9992c..381d399e 100644 --- a/test/getImportMapFromProjectFiles/core/sibling-and-deep/root/node_modules/nested/node_modules/bar/package.json +++ b/test/getImportMapFromProjectFiles/core/sibling-and-deep/root/node_modules/nested/node_modules/bar/package.json @@ -1,4 +1,7 @@ { "module": "bar.js", - "dependencies": {} + "dependencies": {}, + "exports": { + "./": "./" + } } diff --git a/test/getImportMapFromProjectFiles/core/sibling-and-deep/root/node_modules/nested/node_modules/foo/package.json b/test/getImportMapFromProjectFiles/core/sibling-and-deep/root/node_modules/nested/node_modules/foo/package.json index be1eef68..278e5268 100644 --- a/test/getImportMapFromProjectFiles/core/sibling-and-deep/root/node_modules/nested/node_modules/foo/package.json +++ b/test/getImportMapFromProjectFiles/core/sibling-and-deep/root/node_modules/nested/node_modules/foo/package.json @@ -2,5 +2,8 @@ "module": "foo.js", "dependencies": { "bar": "*" + }, + "exports": { + "./": "./" } } diff --git a/test/getImportMapFromProjectFiles/core/sibling-and-deep/root/node_modules/nested/package.json b/test/getImportMapFromProjectFiles/core/sibling-and-deep/root/node_modules/nested/package.json index a6531a3c..d1ec9c74 100644 --- a/test/getImportMapFromProjectFiles/core/sibling-and-deep/root/node_modules/nested/package.json +++ b/test/getImportMapFromProjectFiles/core/sibling-and-deep/root/node_modules/nested/package.json @@ -1,8 +1,10 @@ { - "name": "root", - "type": "module", + "name": "nested", "dependencies": { "foo": "*", "bar": "*" + }, + "exports": { + "./": "./" } } diff --git a/test/getImportMapFromProjectFiles/core/sibling-and-deep/root/package.json b/test/getImportMapFromProjectFiles/core/sibling-and-deep/root/package.json index b9473838..ef8d1457 100644 --- a/test/getImportMapFromProjectFiles/core/sibling-and-deep/root/package.json +++ b/test/getImportMapFromProjectFiles/core/sibling-and-deep/root/package.json @@ -1,7 +1,9 @@ { "name": "root", "module": "index.js", - "type": "module", + "exports": { + "./": "./" + }, "dependencies": { "nested": "*" } diff --git a/test/getImportMapFromProjectFiles/core/sibling-and-deep/sibling-and-deep.test.js b/test/getImportMapFromProjectFiles/core/sibling-and-deep/sibling-and-deep.test.js index ba8406a0..d069e5fb 100644 --- a/test/getImportMapFromProjectFiles/core/sibling-and-deep/sibling-and-deep.test.js +++ b/test/getImportMapFromProjectFiles/core/sibling-and-deep/sibling-and-deep.test.js @@ -9,6 +9,7 @@ const actual = await getImportMapFromProjectFiles({ }) const expected = { imports: { + "nested/": "./node_modules/nested/", "nested": "./node_modules/nested/index", "root/": "./", "root": "./index.js", @@ -18,11 +19,13 @@ const expected = { "bar/": "./node_modules/nested/node_modules/bar/", }, "./node_modules/nested/node_modules/foo/": { + "bar/": "./node_modules/nested/node_modules/bar/", "foo/": "./node_modules/nested/node_modules/foo/", "bar": "./node_modules/nested/node_modules/bar/bar.js", }, "./node_modules/nested/": { - "nested/": "./node_modules/nested/", + "bar/": "./node_modules/nested/node_modules/bar/", + "foo/": "./node_modules/nested/node_modules/foo/", "bar": "./node_modules/nested/node_modules/bar/bar.js", "foo": "./node_modules/nested/node_modules/foo/foo.js", }, diff --git a/test/getImportMapFromProjectFiles/core/symlink/root/node_modules/foo/package.json b/test/getImportMapFromProjectFiles/core/symlink/root/node_modules/foo/package.json index c677d0d6..f0e5670b 100644 --- a/test/getImportMapFromProjectFiles/core/symlink/root/node_modules/foo/package.json +++ b/test/getImportMapFromProjectFiles/core/symlink/root/node_modules/foo/package.json @@ -1,4 +1,5 @@ { + "name": "foo", "module": "index.js", "importmap": { "imports": { diff --git a/test/getImportMapFromProjectFiles/core/symlink/root/project/node_modules/foo/package.json b/test/getImportMapFromProjectFiles/core/symlink/root/project/node_modules/foo/package.json deleted file mode 100644 index 6cbb3669..00000000 --- a/test/getImportMapFromProjectFiles/core/symlink/root/project/node_modules/foo/package.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "module": "index.js" -} diff --git a/test/getImportMapFromProjectFiles/core/symlink/root/project/package.json b/test/getImportMapFromProjectFiles/core/symlink/root/project/package.json deleted file mode 100644 index 759b0a2e..00000000 --- a/test/getImportMapFromProjectFiles/core/symlink/root/project/package.json +++ /dev/null @@ -1,6 +0,0 @@ -{ - "module": "index.js", - "dependencies": { - "foo": "*" - } -} diff --git a/test/getImportMapFromProjectFiles/core/symlink/symlink.test.js b/test/getImportMapFromProjectFiles/core/symlink/symlink.test.js index cb4b1403..72f00ac9 100644 --- a/test/getImportMapFromProjectFiles/core/symlink/symlink.test.js +++ b/test/getImportMapFromProjectFiles/core/symlink/symlink.test.js @@ -9,9 +9,8 @@ const actual = await getImportMapFromProjectFiles({ }) const expected = { imports: { - "root/": "./", - "root": "./index.js", - "foo": "./node_modules/foo/index.js", + root: "./index.js", + foo: "./node_modules/foo/index.js", }, scopes: { "./node_modules/foo/": { diff --git a/test/getImportMapFromProjectFiles/from-js/extensionless-js/extensionless-js.test.js b/test/getImportMapFromProjectFiles/from-js/extensionless-js/extensionless-js.test.js index 588a3f78..15ae240f 100644 --- a/test/getImportMapFromProjectFiles/from-js/extensionless-js/extensionless-js.test.js +++ b/test/getImportMapFromProjectFiles/from-js/extensionless-js/extensionless-js.test.js @@ -9,8 +9,7 @@ const actual = await getImportMapFromProjectFiles({ }) const expected = { imports: { - "root/": "./", - "root": "./index.js", + root: "./index.js", }, scopes: {}, } diff --git a/test/getImportMapFromProjectFiles/included-predicate/included-predicate.test.js b/test/getImportMapFromProjectFiles/included-predicate/included-predicate.test.js index aa1955a6..d70ddd4b 100644 --- a/test/getImportMapFromProjectFiles/included-predicate/included-predicate.test.js +++ b/test/getImportMapFromProjectFiles/included-predicate/included-predicate.test.js @@ -6,11 +6,11 @@ const testDirectoryUrl = resolveUrl("./root/", import.meta.url) const actual = await getImportMapFromProjectFiles({ projectDirectoryUrl: testDirectoryUrl, - packagesSelfReference: false, packageIncludedPredicate: ({ packageName }) => packageName !== "foo", }) const expected = { imports: { + root: "./index", bar: "./node_modules/bar/index", }, scopes: {}, diff --git a/test/getImportMapFromProjectFiles/manual-override/manual-override.test.js b/test/getImportMapFromProjectFiles/manual-override/manual-override.test.js index 3dc98d67..8d56be4c 100644 --- a/test/getImportMapFromProjectFiles/manual-override/manual-override.test.js +++ b/test/getImportMapFromProjectFiles/manual-override/manual-override.test.js @@ -2,7 +2,7 @@ import { assert } from "@jsenv/assert" import { resolveUrl } from "@jsenv/util" import { getImportMapFromProjectFiles } from "@jsenv/node-module-import-map" -const testDirectoryUrl = resolveUrl("./", import.meta.url) +const testDirectoryUrl = resolveUrl("./root/", import.meta.url) const actual = await getImportMapFromProjectFiles({ projectDirectoryUrl: testDirectoryUrl, @@ -14,11 +14,12 @@ const actual = await getImportMapFromProjectFiles({ }, }, }, - packagesSelfReference: false, + jsFiles: false, }) const expected = { imports: { "bar/": "./node_modules/bar/", + "root": "./index", "bar": "./node_modules/bar/bar.js", }, scopes: {}, diff --git a/test/getImportMapFromProjectFiles/manual-override/node_modules/bar/bar.js b/test/getImportMapFromProjectFiles/manual-override/root/node_modules/bar/bar.js similarity index 100% rename from test/getImportMapFromProjectFiles/manual-override/node_modules/bar/bar.js rename to test/getImportMapFromProjectFiles/manual-override/root/node_modules/bar/bar.js diff --git a/test/getImportMapFromProjectFiles/manual-override/node_modules/bar/package.json b/test/getImportMapFromProjectFiles/manual-override/root/node_modules/bar/package.json similarity index 100% rename from test/getImportMapFromProjectFiles/manual-override/node_modules/bar/package.json rename to test/getImportMapFromProjectFiles/manual-override/root/node_modules/bar/package.json diff --git a/test/getImportMapFromProjectFiles/manual-override/package.json b/test/getImportMapFromProjectFiles/manual-override/root/package.json similarity index 100% rename from test/getImportMapFromProjectFiles/manual-override/package.json rename to test/getImportMapFromProjectFiles/manual-override/root/package.json diff --git a/test/getImportMapFromProjectFiles/package-exports-field/exports-and-main/exports-and-main.test.js b/test/getImportMapFromProjectFiles/package-exports-field/exports-and-main/exports-and-main.test.js index 44269ecf..fbb32029 100644 --- a/test/getImportMapFromProjectFiles/package-exports-field/exports-and-main/exports-and-main.test.js +++ b/test/getImportMapFromProjectFiles/package-exports-field/exports-and-main/exports-and-main.test.js @@ -6,10 +6,11 @@ const testDirectoryUrl = resolveUrl("./root/", import.meta.url) const actual = await getImportMapFromProjectFiles({ projectDirectoryUrl: testDirectoryUrl, - packagesSelfReference: false, + jsFiles: false, }) const expected = { imports: { + whatever: "./index", foo: "./node_modules/foo/file.js", }, scopes: {}, diff --git a/test/getImportMapFromProjectFiles/package-exports-field/exports-complex/exports-complex.test.js b/test/getImportMapFromProjectFiles/package-exports-field/exports-complex/exports-complex.test.js index 3c9ff291..9659769e 100644 --- a/test/getImportMapFromProjectFiles/package-exports-field/exports-complex/exports-complex.test.js +++ b/test/getImportMapFromProjectFiles/package-exports-field/exports-complex/exports-complex.test.js @@ -2,23 +2,25 @@ import { assert } from "@jsenv/assert" import { resolveUrl } from "@jsenv/util" import { getImportMapFromProjectFiles } from "@jsenv/node-module-import-map" -const testDirectoryUrl = resolveUrl("./", import.meta.url) +const testDirectoryUrl = resolveUrl("./root/", import.meta.url) -const getImportMap = async ({ packagesExportsPreference } = {}) => { +const getImportMap = async ({ runtime, moduleFormat } = {}) => { return getImportMapFromProjectFiles({ projectDirectoryUrl: testDirectoryUrl, - packagesSelfReference: false, - packagesExportsPreference, + jsFiles: false, + moduleFormat, + runtime, }) } { const actual = await getImportMap({ - packagesExportsPreference: ["node", "import", "require"], + runtime: "node", }) const expected = { imports: { "foo/dist/": "./node_modules/foo/dist/", + "whatever": "./index", "foo": "./node_modules/foo/dist/es/rollup.js", }, scopes: {}, @@ -28,11 +30,13 @@ const getImportMap = async ({ packagesExportsPreference } = {}) => { { const actual = await getImportMap({ - packagesExportsPreference: ["node", "require"], + runtime: "node", + moduleFormat: "cjs", }) const expected = { imports: { "foo/dist/": "./node_modules/foo/dist/", + "whatever": "./index", "foo": "./node_modules/foo/dist/rollup.js", }, scopes: {}, @@ -42,11 +46,13 @@ const getImportMap = async ({ packagesExportsPreference } = {}) => { { const actual = await getImportMap({ - packagesExportsPreference: ["node"], + runtime: "node", + moduleFormat: "other", }) const expected = { imports: { "foo/dist/": "./node_modules/foo/dist/", + "whatever": "./index", "foo": "./node_modules/foo/file.cjs", }, scopes: {}, @@ -59,6 +65,7 @@ const getImportMap = async ({ packagesExportsPreference } = {}) => { const expected = { imports: { "foo/dist/": "./node_modules/foo/dist/", + "whatever": "./index", "foo": "./node_modules/foo/dist/es/rollup.browser.js", }, scopes: {}, diff --git a/test/getImportMapFromProjectFiles/package-exports-field/exports-complex/node_modules/foo/file.cjs b/test/getImportMapFromProjectFiles/package-exports-field/exports-complex/root/node_modules/foo/file.cjs similarity index 100% rename from test/getImportMapFromProjectFiles/package-exports-field/exports-complex/node_modules/foo/file.cjs rename to test/getImportMapFromProjectFiles/package-exports-field/exports-complex/root/node_modules/foo/file.cjs diff --git a/test/getImportMapFromProjectFiles/package-exports-field/exports-complex/node_modules/foo/package.json b/test/getImportMapFromProjectFiles/package-exports-field/exports-complex/root/node_modules/foo/package.json similarity index 100% rename from test/getImportMapFromProjectFiles/package-exports-field/exports-complex/node_modules/foo/package.json rename to test/getImportMapFromProjectFiles/package-exports-field/exports-complex/root/node_modules/foo/package.json diff --git a/test/getImportMapFromProjectFiles/package-exports-field/exports-complex/package.json b/test/getImportMapFromProjectFiles/package-exports-field/exports-complex/root/package.json similarity index 100% rename from test/getImportMapFromProjectFiles/package-exports-field/exports-complex/package.json rename to test/getImportMapFromProjectFiles/package-exports-field/exports-complex/root/package.json diff --git a/test/getImportMapFromProjectFiles/package-exports-field/exports-condition-nested/exports-condition-nested.test.js b/test/getImportMapFromProjectFiles/package-exports-field/exports-condition-nested/exports-condition-nested.test.js index a3a29b48..9e3ca3d6 100644 --- a/test/getImportMapFromProjectFiles/package-exports-field/exports-condition-nested/exports-condition-nested.test.js +++ b/test/getImportMapFromProjectFiles/package-exports-field/exports-condition-nested/exports-condition-nested.test.js @@ -8,11 +8,12 @@ const testDirectoryUrl = resolveUrl("./root/", import.meta.url) const importMap = await getImportMapFromProjectFiles({ projectDirectoryUrl: testDirectoryUrl, runtime: "node", - packagesSelfReference: false, + jsFiles: false, }) const actual = importMap const expected = { imports: { + root: "./index", foo: "./node_modules/foo/feature-node.mjs", }, scopes: {}, @@ -24,11 +25,12 @@ const testDirectoryUrl = resolveUrl("./root/", import.meta.url) const importMap = await getImportMapFromProjectFiles({ projectDirectoryUrl: testDirectoryUrl, runtime: "browser", - packagesSelfReference: false, + jsFiles: false, }) const actual = importMap const expected = { imports: { + root: "./index", foo: "./node_modules/foo/feature.mjs", }, scopes: {}, diff --git a/test/getImportMapFromProjectFiles/package-exports-field/exports-directory-scoped/exports-directory-scoped.test.js b/test/getImportMapFromProjectFiles/package-exports-field/exports-directory-scoped/exports-directory-scoped.test.js index a3cd2efa..a320b779 100644 --- a/test/getImportMapFromProjectFiles/package-exports-field/exports-directory-scoped/exports-directory-scoped.test.js +++ b/test/getImportMapFromProjectFiles/package-exports-field/exports-directory-scoped/exports-directory-scoped.test.js @@ -6,11 +6,12 @@ const testDirectoryUrl = resolveUrl("./root/", import.meta.url) const actual = await getImportMapFromProjectFiles({ projectDirectoryUrl: testDirectoryUrl, - packagesSelfReference: false, + jsFiles: false, }) const expected = { imports: { "foo/ding": "./node_modules/foo/dong", + "root": "./index", "foo": "./node_modules/foo/index.js", }, scopes: { diff --git a/test/getImportMapFromProjectFiles/package-exports-field/exports-directory/exports-directory.test.js b/test/getImportMapFromProjectFiles/package-exports-field/exports-directory/exports-directory.test.js index c4be3229..39cd3a18 100644 --- a/test/getImportMapFromProjectFiles/package-exports-field/exports-directory/exports-directory.test.js +++ b/test/getImportMapFromProjectFiles/package-exports-field/exports-directory/exports-directory.test.js @@ -2,16 +2,17 @@ import { assert } from "@jsenv/assert" import { resolveUrl } from "@jsenv/util" import { getImportMapFromProjectFiles } from "@jsenv/node-module-import-map" -const testDirectoryUrl = resolveUrl("./", import.meta.url) +const testDirectoryUrl = resolveUrl("./root/", import.meta.url) const actual = await getImportMapFromProjectFiles({ projectDirectoryUrl: testDirectoryUrl, - packagesSelfReference: false, + jsFiles: false, }) const expected = { imports: { "@jsenv/whatever/": "./node_modules/@jsenv/whatever/", "@jsenv/whatever": "./node_modules/@jsenv/whatever/index.js", + "root": "./index", }, scopes: {}, } diff --git a/test/getImportMapFromProjectFiles/core/symlink/root/project/index.js b/test/getImportMapFromProjectFiles/package-exports-field/exports-directory/root/node_modules/@jsenv/whatever/index.js similarity index 100% rename from test/getImportMapFromProjectFiles/core/symlink/root/project/index.js rename to test/getImportMapFromProjectFiles/package-exports-field/exports-directory/root/node_modules/@jsenv/whatever/index.js diff --git a/test/getImportMapFromProjectFiles/package-exports-field/exports-directory/node_modules/@jsenv/whatever/package.json b/test/getImportMapFromProjectFiles/package-exports-field/exports-directory/root/node_modules/@jsenv/whatever/package.json similarity index 100% rename from test/getImportMapFromProjectFiles/package-exports-field/exports-directory/node_modules/@jsenv/whatever/package.json rename to test/getImportMapFromProjectFiles/package-exports-field/exports-directory/root/node_modules/@jsenv/whatever/package.json diff --git a/test/getImportMapFromProjectFiles/package-exports-field/exports-directory/package.json b/test/getImportMapFromProjectFiles/package-exports-field/exports-directory/root/package.json similarity index 100% rename from test/getImportMapFromProjectFiles/package-exports-field/exports-directory/package.json rename to test/getImportMapFromProjectFiles/package-exports-field/exports-directory/root/package.json diff --git a/test/getImportMapFromProjectFiles/package-exports-field/exports-file-conditional/exports-file-conditional.test.js b/test/getImportMapFromProjectFiles/package-exports-field/exports-file-conditional/exports-file-conditional.test.js index be67b1a3..b064d002 100644 --- a/test/getImportMapFromProjectFiles/package-exports-field/exports-file-conditional/exports-file-conditional.test.js +++ b/test/getImportMapFromProjectFiles/package-exports-field/exports-file-conditional/exports-file-conditional.test.js @@ -2,18 +2,19 @@ import { assert } from "@jsenv/assert" import { resolveUrl } from "@jsenv/util" import { getImportMapFromProjectFiles } from "@jsenv/node-module-import-map" -const testDirectoryUrl = resolveUrl("./", import.meta.url) +const testDirectoryUrl = resolveUrl("./root/", import.meta.url) { const importMap = await getImportMapFromProjectFiles({ projectDirectoryUrl: testDirectoryUrl, - packagesExportsPreference: ["browser"], - packagesSelfReference: false, + runtime: "browser", + jsFiles: false, }) const actual = importMap const expected = { imports: { "foo/file.js": "./node_modules/foo/file.browser.js", + "root": "./index", "foo": "./node_modules/foo/index", }, scopes: {}, @@ -24,13 +25,14 @@ const testDirectoryUrl = resolveUrl("./", import.meta.url) { const importMap = await getImportMapFromProjectFiles({ projectDirectoryUrl: testDirectoryUrl, - packagesExportsPreference: [], - packagesSelfReference: false, + runtime: "other", + jsFiles: false, }) const actual = importMap const expected = { imports: { "foo/file.js": "./node_modules/foo/file.default.js", + "root": "./index", "foo": "./node_modules/foo/index", }, scopes: {}, diff --git a/test/getImportMapFromProjectFiles/package-exports-field/exports-file-conditional/node_modules/foo/package.json b/test/getImportMapFromProjectFiles/package-exports-field/exports-file-conditional/root/node_modules/foo/package.json similarity index 100% rename from test/getImportMapFromProjectFiles/package-exports-field/exports-file-conditional/node_modules/foo/package.json rename to test/getImportMapFromProjectFiles/package-exports-field/exports-file-conditional/root/node_modules/foo/package.json diff --git a/test/getImportMapFromProjectFiles/package-exports-field/exports-file-conditional/package.json b/test/getImportMapFromProjectFiles/package-exports-field/exports-file-conditional/root/package.json similarity index 100% rename from test/getImportMapFromProjectFiles/package-exports-field/exports-file-conditional/package.json rename to test/getImportMapFromProjectFiles/package-exports-field/exports-file-conditional/root/package.json diff --git a/test/getImportMapFromProjectFiles/package-exports-field/exports-file-deep-2/exports-file-deep-2.test.js b/test/getImportMapFromProjectFiles/package-exports-field/exports-file-deep-2/exports-file-deep-2.test.js index 92e73588..042c724a 100644 --- a/test/getImportMapFromProjectFiles/package-exports-field/exports-file-deep-2/exports-file-deep-2.test.js +++ b/test/getImportMapFromProjectFiles/package-exports-field/exports-file-deep-2/exports-file-deep-2.test.js @@ -2,15 +2,16 @@ import { assert } from "@jsenv/assert" import { resolveUrl } from "@jsenv/util" import { getImportMapFromProjectFiles } from "@jsenv/node-module-import-map" -const testDirectoryUrl = resolveUrl("./", import.meta.url) +const testDirectoryUrl = resolveUrl("./root/", import.meta.url) const importMap = await getImportMapFromProjectFiles({ projectDirectoryUrl: testDirectoryUrl, - packagesSelfReference: false, + jsFiles: false, }) const actual = importMap const expected = { imports: { + root: "./index", foo: "./node_modules/foo/index", }, scopes: { diff --git a/test/getImportMapFromProjectFiles/package-exports-field/exports-file-deep-2/node_modules/foo/node_modules/bar/package.json b/test/getImportMapFromProjectFiles/package-exports-field/exports-file-deep-2/root/node_modules/foo/node_modules/bar/package.json similarity index 100% rename from test/getImportMapFromProjectFiles/package-exports-field/exports-file-deep-2/node_modules/foo/node_modules/bar/package.json rename to test/getImportMapFromProjectFiles/package-exports-field/exports-file-deep-2/root/node_modules/foo/node_modules/bar/package.json diff --git a/test/getImportMapFromProjectFiles/package-exports-field/exports-file-deep-2/node_modules/foo/package.json b/test/getImportMapFromProjectFiles/package-exports-field/exports-file-deep-2/root/node_modules/foo/package.json similarity index 100% rename from test/getImportMapFromProjectFiles/package-exports-field/exports-file-deep-2/node_modules/foo/package.json rename to test/getImportMapFromProjectFiles/package-exports-field/exports-file-deep-2/root/node_modules/foo/package.json diff --git a/test/getImportMapFromProjectFiles/package-exports-field/exports-file-deep-2/package.json b/test/getImportMapFromProjectFiles/package-exports-field/exports-file-deep-2/root/package.json similarity index 100% rename from test/getImportMapFromProjectFiles/package-exports-field/exports-file-deep-2/package.json rename to test/getImportMapFromProjectFiles/package-exports-field/exports-file-deep-2/root/package.json diff --git a/test/getImportMapFromProjectFiles/package-exports-field/exports-file-deep/exports-file-deep.test.js b/test/getImportMapFromProjectFiles/package-exports-field/exports-file-deep/exports-file-deep.test.js index 071735dd..cead984c 100644 --- a/test/getImportMapFromProjectFiles/package-exports-field/exports-file-deep/exports-file-deep.test.js +++ b/test/getImportMapFromProjectFiles/package-exports-field/exports-file-deep/exports-file-deep.test.js @@ -2,15 +2,16 @@ import { assert } from "@jsenv/assert" import { resolveUrl } from "@jsenv/util" import { getImportMapFromProjectFiles } from "@jsenv/node-module-import-map" -const testDirectoryUrl = resolveUrl("./", import.meta.url) +const testDirectoryUrl = resolveUrl("./root/", import.meta.url) const importMap = await getImportMapFromProjectFiles({ projectDirectoryUrl: testDirectoryUrl, - packagesSelfReference: false, + jsFiles: false, }) const actual = importMap const expected = { imports: { + root: "./index", foo: "./node_modules/foo/index", }, scopes: { diff --git a/test/getImportMapFromProjectFiles/package-exports-field/exports-file-deep/node_modules/bar/package.json b/test/getImportMapFromProjectFiles/package-exports-field/exports-file-deep/root/node_modules/bar/package.json similarity index 100% rename from test/getImportMapFromProjectFiles/package-exports-field/exports-file-deep/node_modules/bar/package.json rename to test/getImportMapFromProjectFiles/package-exports-field/exports-file-deep/root/node_modules/bar/package.json diff --git a/test/getImportMapFromProjectFiles/package-exports-field/exports-file-deep/node_modules/foo/package.json b/test/getImportMapFromProjectFiles/package-exports-field/exports-file-deep/root/node_modules/foo/package.json similarity index 100% rename from test/getImportMapFromProjectFiles/package-exports-field/exports-file-deep/node_modules/foo/package.json rename to test/getImportMapFromProjectFiles/package-exports-field/exports-file-deep/root/node_modules/foo/package.json diff --git a/test/getImportMapFromProjectFiles/package-exports-field/exports-file-deep/package.json b/test/getImportMapFromProjectFiles/package-exports-field/exports-file-deep/root/package.json similarity index 100% rename from test/getImportMapFromProjectFiles/package-exports-field/exports-file-deep/package.json rename to test/getImportMapFromProjectFiles/package-exports-field/exports-file-deep/root/package.json diff --git a/test/getImportMapFromProjectFiles/package-exports-field/exports-file/exports-file.test.js b/test/getImportMapFromProjectFiles/package-exports-field/exports-file/exports-file.test.js index 91e3507a..df8b572f 100644 --- a/test/getImportMapFromProjectFiles/package-exports-field/exports-file/exports-file.test.js +++ b/test/getImportMapFromProjectFiles/package-exports-field/exports-file/exports-file.test.js @@ -2,16 +2,17 @@ import { assert } from "@jsenv/assert" import { resolveUrl } from "@jsenv/util" import { getImportMapFromProjectFiles } from "@jsenv/node-module-import-map" -const testDirectoryUrl = resolveUrl("./", import.meta.url) +const testDirectoryUrl = resolveUrl("./root/", import.meta.url) const importMap = await getImportMapFromProjectFiles({ projectDirectoryUrl: testDirectoryUrl, - packagesSelfReference: false, + jsFiles: false, }) const actual = importMap const expected = { imports: { "foo/file.js": "./node_modules/foo/src/file.js", + "root": "./index", "foo": "./node_modules/foo/index.js", }, scopes: {}, diff --git a/test/getImportMapFromProjectFiles/core/symlink/root/project/node_modules/foo/index.js b/test/getImportMapFromProjectFiles/package-exports-field/exports-file/root/node_modules/foo/index.js similarity index 100% rename from test/getImportMapFromProjectFiles/core/symlink/root/project/node_modules/foo/index.js rename to test/getImportMapFromProjectFiles/package-exports-field/exports-file/root/node_modules/foo/index.js diff --git a/test/getImportMapFromProjectFiles/package-exports-field/exports-file/node_modules/foo/package.json b/test/getImportMapFromProjectFiles/package-exports-field/exports-file/root/node_modules/foo/package.json similarity index 100% rename from test/getImportMapFromProjectFiles/package-exports-field/exports-file/node_modules/foo/package.json rename to test/getImportMapFromProjectFiles/package-exports-field/exports-file/root/node_modules/foo/package.json diff --git a/test/getImportMapFromProjectFiles/package-exports-field/exports-file/package.json b/test/getImportMapFromProjectFiles/package-exports-field/exports-file/root/package.json similarity index 100% rename from test/getImportMapFromProjectFiles/package-exports-field/exports-file/package.json rename to test/getImportMapFromProjectFiles/package-exports-field/exports-file/root/package.json diff --git a/test/getImportMapFromProjectFiles/package-exports-field/exports-pattern-directory/exports-pattern-directory.test.js b/test/getImportMapFromProjectFiles/package-exports-field/exports-pattern-directory/exports-pattern-directory.test.js index e5acd03a..8b530843 100644 --- a/test/getImportMapFromProjectFiles/package-exports-field/exports-pattern-directory/exports-pattern-directory.test.js +++ b/test/getImportMapFromProjectFiles/package-exports-field/exports-pattern-directory/exports-pattern-directory.test.js @@ -2,15 +2,15 @@ import { assert } from "@jsenv/assert" import { resolveUrl } from "@jsenv/util" import { getImportMapFromProjectFiles } from "@jsenv/node-module-import-map" -const testDirectoryUrl = resolveUrl("./", import.meta.url) +const testDirectoryUrl = resolveUrl("./root/", import.meta.url) const actual = await getImportMapFromProjectFiles({ projectDirectoryUrl: testDirectoryUrl, - packagesSelfReference: false, }) const expected = { imports: { "foo/": "./node_modules/foo/", + "root": "./index", "foo": "./node_modules/foo/index", }, scopes: {}, diff --git a/test/getImportMapFromProjectFiles/package-exports-field/exports-pattern-directory/node_modules/foo/package.json b/test/getImportMapFromProjectFiles/package-exports-field/exports-pattern-directory/root/node_modules/foo/package.json similarity index 100% rename from test/getImportMapFromProjectFiles/package-exports-field/exports-pattern-directory/node_modules/foo/package.json rename to test/getImportMapFromProjectFiles/package-exports-field/exports-pattern-directory/root/node_modules/foo/package.json diff --git a/test/getImportMapFromProjectFiles/package-exports-field/exports-pattern-directory/package.json b/test/getImportMapFromProjectFiles/package-exports-field/exports-pattern-directory/root/package.json similarity index 100% rename from test/getImportMapFromProjectFiles/package-exports-field/exports-pattern-directory/package.json rename to test/getImportMapFromProjectFiles/package-exports-field/exports-pattern-directory/root/package.json diff --git a/test/getImportMapFromProjectFiles/package-exports-field/exports-pattern-extensionless/exports-pattern-extensionless.test.js b/test/getImportMapFromProjectFiles/package-exports-field/exports-pattern-extensionless/exports-pattern-extensionless.test.js index f108374b..7173db17 100644 --- a/test/getImportMapFromProjectFiles/package-exports-field/exports-pattern-extensionless/exports-pattern-extensionless.test.js +++ b/test/getImportMapFromProjectFiles/package-exports-field/exports-pattern-extensionless/exports-pattern-extensionless.test.js @@ -2,14 +2,14 @@ import { assert } from "@jsenv/assert" import { resolveUrl } from "@jsenv/util" import { getImportMapFromProjectFiles } from "@jsenv/node-module-import-map" -const testDirectoryUrl = resolveUrl("./", import.meta.url) +const testDirectoryUrl = resolveUrl("./root/", import.meta.url) const actual = await getImportMapFromProjectFiles({ projectDirectoryUrl: testDirectoryUrl, - packagesSelfReference: false, }) const expected = { imports: { + root: "./index", foo: "./node_modules/foo/index", }, scopes: {}, diff --git a/test/getImportMapFromProjectFiles/package-exports-field/exports-pattern-extensionless/node_modules/foo/package.json b/test/getImportMapFromProjectFiles/package-exports-field/exports-pattern-extensionless/root/node_modules/foo/package.json similarity index 100% rename from test/getImportMapFromProjectFiles/package-exports-field/exports-pattern-extensionless/node_modules/foo/package.json rename to test/getImportMapFromProjectFiles/package-exports-field/exports-pattern-extensionless/root/node_modules/foo/package.json diff --git a/test/getImportMapFromProjectFiles/package-exports-field/exports-pattern-extensionless/package.json b/test/getImportMapFromProjectFiles/package-exports-field/exports-pattern-extensionless/root/package.json similarity index 100% rename from test/getImportMapFromProjectFiles/package-exports-field/exports-pattern-extensionless/package.json rename to test/getImportMapFromProjectFiles/package-exports-field/exports-pattern-extensionless/root/package.json diff --git a/test/getImportMapFromProjectFiles/package-exports-field/exports-string/exports-string.test.js b/test/getImportMapFromProjectFiles/package-exports-field/exports-string/exports-string.test.js index ad58a847..9263362a 100644 --- a/test/getImportMapFromProjectFiles/package-exports-field/exports-string/exports-string.test.js +++ b/test/getImportMapFromProjectFiles/package-exports-field/exports-string/exports-string.test.js @@ -2,15 +2,16 @@ import { assert } from "@jsenv/assert" import { resolveUrl } from "@jsenv/util" import { getImportMapFromProjectFiles } from "@jsenv/node-module-import-map" -const testDirectoryUrl = resolveUrl("./", import.meta.url) +const testDirectoryUrl = resolveUrl("./root/", import.meta.url) const importMap = await getImportMapFromProjectFiles({ projectDirectoryUrl: testDirectoryUrl, - packagesSelfReference: false, + jsFiles: false, }) const actual = importMap const expected = { imports: { + root: "./index", foo: "./node_modules/foo/foo.js", }, scopes: {}, diff --git a/test/getImportMapFromProjectFiles/package-exports-field/exports-string/node_modules/foo/package.json b/test/getImportMapFromProjectFiles/package-exports-field/exports-string/root/node_modules/foo/package.json similarity index 100% rename from test/getImportMapFromProjectFiles/package-exports-field/exports-string/node_modules/foo/package.json rename to test/getImportMapFromProjectFiles/package-exports-field/exports-string/root/node_modules/foo/package.json diff --git a/test/getImportMapFromProjectFiles/package-exports-field/exports-string/package.json b/test/getImportMapFromProjectFiles/package-exports-field/exports-string/root/package.json similarity index 100% rename from test/getImportMapFromProjectFiles/package-exports-field/exports-string/package.json rename to test/getImportMapFromProjectFiles/package-exports-field/exports-string/root/package.json diff --git a/test/getImportMapFromProjectFiles/package-exports-field/exports-sugar-conditional/exports-sugar-conditional.test.js b/test/getImportMapFromProjectFiles/package-exports-field/exports-sugar-conditional/exports-sugar-conditional.test.js index 9d85bd49..d0a516dc 100644 --- a/test/getImportMapFromProjectFiles/package-exports-field/exports-sugar-conditional/exports-sugar-conditional.test.js +++ b/test/getImportMapFromProjectFiles/package-exports-field/exports-sugar-conditional/exports-sugar-conditional.test.js @@ -2,17 +2,17 @@ import { assert } from "@jsenv/assert" import { resolveUrl } from "@jsenv/util" import { getImportMapFromProjectFiles } from "@jsenv/node-module-import-map" -const testDirectoryUrl = resolveUrl("./", import.meta.url) +const testDirectoryUrl = resolveUrl("./root/", import.meta.url) { const importMap = await getImportMapFromProjectFiles({ projectDirectoryUrl: testDirectoryUrl, - packagesExportsPreference: ["node"], - packagesSelfReference: false, + runtime: "node", }) const actual = importMap const expected = { imports: { + root: "./index", foo: "./node_modules/foo/index.default.js", }, scopes: {}, @@ -23,12 +23,12 @@ const testDirectoryUrl = resolveUrl("./", import.meta.url) { const importMap = await getImportMapFromProjectFiles({ projectDirectoryUrl: testDirectoryUrl, - packagesExportsPreference: ["browser"], - packagesSelfReference: false, + runtime: "browser", }) const actual = importMap const expected = { imports: { + root: "./index", foo: "./node_modules/foo/index.browser.js", }, scopes: {}, diff --git a/test/getImportMapFromProjectFiles/package-exports-field/exports-sugar-conditional/node_modules/foo/package.json b/test/getImportMapFromProjectFiles/package-exports-field/exports-sugar-conditional/root/node_modules/foo/package.json similarity index 100% rename from test/getImportMapFromProjectFiles/package-exports-field/exports-sugar-conditional/node_modules/foo/package.json rename to test/getImportMapFromProjectFiles/package-exports-field/exports-sugar-conditional/root/node_modules/foo/package.json diff --git a/test/getImportMapFromProjectFiles/package-exports-field/exports-sugar-conditional/package.json b/test/getImportMapFromProjectFiles/package-exports-field/exports-sugar-conditional/root/package.json similarity index 100% rename from test/getImportMapFromProjectFiles/package-exports-field/exports-sugar-conditional/package.json rename to test/getImportMapFromProjectFiles/package-exports-field/exports-sugar-conditional/root/package.json diff --git a/test/getImportMapFromProjectFiles/package-exports-field/exports-sugar/exports-sugar.test.js b/test/getImportMapFromProjectFiles/package-exports-field/exports-sugar/exports-sugar.test.js index ad58a847..9263362a 100644 --- a/test/getImportMapFromProjectFiles/package-exports-field/exports-sugar/exports-sugar.test.js +++ b/test/getImportMapFromProjectFiles/package-exports-field/exports-sugar/exports-sugar.test.js @@ -2,15 +2,16 @@ import { assert } from "@jsenv/assert" import { resolveUrl } from "@jsenv/util" import { getImportMapFromProjectFiles } from "@jsenv/node-module-import-map" -const testDirectoryUrl = resolveUrl("./", import.meta.url) +const testDirectoryUrl = resolveUrl("./root/", import.meta.url) const importMap = await getImportMapFromProjectFiles({ projectDirectoryUrl: testDirectoryUrl, - packagesSelfReference: false, + jsFiles: false, }) const actual = importMap const expected = { imports: { + root: "./index", foo: "./node_modules/foo/foo.js", }, scopes: {}, diff --git a/test/getImportMapFromProjectFiles/package-exports-field/exports-sugar/node_modules/foo/package.json b/test/getImportMapFromProjectFiles/package-exports-field/exports-sugar/root/node_modules/foo/package.json similarity index 100% rename from test/getImportMapFromProjectFiles/package-exports-field/exports-sugar/node_modules/foo/package.json rename to test/getImportMapFromProjectFiles/package-exports-field/exports-sugar/root/node_modules/foo/package.json diff --git a/test/getImportMapFromProjectFiles/package-exports-field/exports-sugar/package.json b/test/getImportMapFromProjectFiles/package-exports-field/exports-sugar/root/package.json similarity index 100% rename from test/getImportMapFromProjectFiles/package-exports-field/exports-sugar/package.json rename to test/getImportMapFromProjectFiles/package-exports-field/exports-sugar/root/package.json diff --git a/test/getImportMapFromProjectFiles/package-importmap-field/importmap-scope/importmap-scope.test.js b/test/getImportMapFromProjectFiles/package-importmap-field/importmap-scope/importmap-scope.test.js index 9ce4a76c..40eabf72 100644 --- a/test/getImportMapFromProjectFiles/package-importmap-field/importmap-scope/importmap-scope.test.js +++ b/test/getImportMapFromProjectFiles/package-importmap-field/importmap-scope/importmap-scope.test.js @@ -6,10 +6,11 @@ const testDirectoryUrl = resolveUrl("./root/", import.meta.url) const actual = await getImportMapFromProjectFiles({ projectDirectoryUrl: testDirectoryUrl, - packagesSelfReference: false, + jsFiles: false, }) const expected = { imports: { + root: "./index", foo: "./node_modules/foo/index", }, scopes: { diff --git a/test/getImportMapFromProjectFiles/package-importmap-field/importmap-top-level/importmap-top-level.test.js b/test/getImportMapFromProjectFiles/package-importmap-field/importmap-top-level/importmap-top-level.test.js index 83d36e36..dd16f5da 100644 --- a/test/getImportMapFromProjectFiles/package-importmap-field/importmap-top-level/importmap-top-level.test.js +++ b/test/getImportMapFromProjectFiles/package-importmap-field/importmap-top-level/importmap-top-level.test.js @@ -6,10 +6,11 @@ const testDirectoryUrl = resolveUrl("./root/", import.meta.url) const actual = await getImportMapFromProjectFiles({ projectDirectoryUrl: testDirectoryUrl, - packagesSelfReference: false, + jsFiles: false, }) const expected = { imports: { + root: "./index", foo: "./node_modules/foo/index", }, scopes: { diff --git a/test/getImportMapFromProjectFiles/package-main-field/main-directory-trailing/main-directory-trailing.test.js b/test/getImportMapFromProjectFiles/package-main-field/main-directory-trailing/main-directory-trailing.test.js index 90721172..e36c29fb 100644 --- a/test/getImportMapFromProjectFiles/package-main-field/main-directory-trailing/main-directory-trailing.test.js +++ b/test/getImportMapFromProjectFiles/package-main-field/main-directory-trailing/main-directory-trailing.test.js @@ -2,15 +2,16 @@ import { assert } from "@jsenv/assert" import { resolveUrl } from "@jsenv/util" import { getImportMapFromProjectFiles } from "@jsenv/node-module-import-map" -const testDirectoryUrl = resolveUrl("./", import.meta.url) +const testDirectoryUrl = resolveUrl("./root/", import.meta.url) const actual = await getImportMapFromProjectFiles({ projectDirectoryUrl: testDirectoryUrl, - packagesSelfReference: false, + jsFiles: false, }) const expected = { imports: { "main-folder-trailing": "./node_modules/main-folder-trailing/lib/index.js", + "root": "./index", }, scopes: {}, } diff --git a/test/getImportMapFromProjectFiles/package-exports-field/exports-directory/node_modules/@jsenv/whatever/index.js b/test/getImportMapFromProjectFiles/package-main-field/main-directory-trailing/root/node_modules/main-folder-trailing/lib/index.js similarity index 100% rename from test/getImportMapFromProjectFiles/package-exports-field/exports-directory/node_modules/@jsenv/whatever/index.js rename to test/getImportMapFromProjectFiles/package-main-field/main-directory-trailing/root/node_modules/main-folder-trailing/lib/index.js diff --git a/test/getImportMapFromProjectFiles/package-main-field/main-directory-trailing/node_modules/main-folder-trailing/package.json b/test/getImportMapFromProjectFiles/package-main-field/main-directory-trailing/root/node_modules/main-folder-trailing/package.json similarity index 100% rename from test/getImportMapFromProjectFiles/package-main-field/main-directory-trailing/node_modules/main-folder-trailing/package.json rename to test/getImportMapFromProjectFiles/package-main-field/main-directory-trailing/root/node_modules/main-folder-trailing/package.json diff --git a/test/getImportMapFromProjectFiles/package-main-field/main-directory-trailing/package.json b/test/getImportMapFromProjectFiles/package-main-field/main-directory-trailing/root/package.json similarity index 100% rename from test/getImportMapFromProjectFiles/package-main-field/main-directory-trailing/package.json rename to test/getImportMapFromProjectFiles/package-main-field/main-directory-trailing/root/package.json diff --git a/test/getImportMapFromProjectFiles/package-main-field/main-directory/main-directory.test.js b/test/getImportMapFromProjectFiles/package-main-field/main-directory/main-directory.test.js index 2b5a9ac0..90ebfaa8 100644 --- a/test/getImportMapFromProjectFiles/package-main-field/main-directory/main-directory.test.js +++ b/test/getImportMapFromProjectFiles/package-main-field/main-directory/main-directory.test.js @@ -2,15 +2,15 @@ import { assert } from "@jsenv/assert" import { resolveUrl } from "@jsenv/util" import { getImportMapFromProjectFiles } from "@jsenv/node-module-import-map" -const testDirectoryUrl = resolveUrl("./", import.meta.url) +const testDirectoryUrl = resolveUrl("./root/", import.meta.url) const actual = await getImportMapFromProjectFiles({ projectDirectoryUrl: testDirectoryUrl, - packagesSelfReference: false, }) const expected = { imports: { "main-directory": "./node_modules/main-directory/lib/index.js", + "root": "./index", }, scopes: {}, } diff --git a/test/getImportMapFromProjectFiles/package-exports-field/exports-file/node_modules/foo/index.js b/test/getImportMapFromProjectFiles/package-main-field/main-directory/root/node_modules/main-directory/lib/index.js similarity index 100% rename from test/getImportMapFromProjectFiles/package-exports-field/exports-file/node_modules/foo/index.js rename to test/getImportMapFromProjectFiles/package-main-field/main-directory/root/node_modules/main-directory/lib/index.js diff --git a/test/getImportMapFromProjectFiles/package-main-field/main-directory/node_modules/main-directory/package.json b/test/getImportMapFromProjectFiles/package-main-field/main-directory/root/node_modules/main-directory/package.json similarity index 100% rename from test/getImportMapFromProjectFiles/package-main-field/main-directory/node_modules/main-directory/package.json rename to test/getImportMapFromProjectFiles/package-main-field/main-directory/root/node_modules/main-directory/package.json diff --git a/test/getImportMapFromProjectFiles/package-main-field/main-directory/package.json b/test/getImportMapFromProjectFiles/package-main-field/main-directory/root/package.json similarity index 100% rename from test/getImportMapFromProjectFiles/package-main-field/main-directory/package.json rename to test/getImportMapFromProjectFiles/package-main-field/main-directory/root/package.json diff --git a/test/getImportMapFromProjectFiles/package-main-field/main-jsnext/main-jsnext.test.js b/test/getImportMapFromProjectFiles/package-main-field/main-jsnext/main-jsnext.test.js index ca481cc6..a36f5068 100644 --- a/test/getImportMapFromProjectFiles/package-main-field/main-jsnext/main-jsnext.test.js +++ b/test/getImportMapFromProjectFiles/package-main-field/main-jsnext/main-jsnext.test.js @@ -2,15 +2,16 @@ import { assert } from "@jsenv/assert" import { resolveUrl } from "@jsenv/util" import { getImportMapFromProjectFiles } from "@jsenv/node-module-import-map" -const testDirectoryUrl = resolveUrl("./", import.meta.url) +const testDirectoryUrl = resolveUrl("./root/", import.meta.url) const actual = await getImportMapFromProjectFiles({ projectDirectoryUrl: testDirectoryUrl, - packagesSelfReference: false, + jsFiles: false, }) const expected = { imports: { "main-jsnext": "./node_modules/main-jsnext/jsnext.js", + "root": "./index", }, scopes: {}, } diff --git a/test/getImportMapFromProjectFiles/package-main-field/main-jsnext/node_modules/main-jsnext/jsnext.js b/test/getImportMapFromProjectFiles/package-main-field/main-jsnext/root/node_modules/main-jsnext/jsnext.js similarity index 100% rename from test/getImportMapFromProjectFiles/package-main-field/main-jsnext/node_modules/main-jsnext/jsnext.js rename to test/getImportMapFromProjectFiles/package-main-field/main-jsnext/root/node_modules/main-jsnext/jsnext.js diff --git a/test/getImportMapFromProjectFiles/package-main-field/main-jsnext/node_modules/main-jsnext/package.json b/test/getImportMapFromProjectFiles/package-main-field/main-jsnext/root/node_modules/main-jsnext/package.json similarity index 100% rename from test/getImportMapFromProjectFiles/package-main-field/main-jsnext/node_modules/main-jsnext/package.json rename to test/getImportMapFromProjectFiles/package-main-field/main-jsnext/root/node_modules/main-jsnext/package.json diff --git a/test/getImportMapFromProjectFiles/package-main-field/main-jsnext/package.json b/test/getImportMapFromProjectFiles/package-main-field/main-jsnext/root/package.json similarity index 100% rename from test/getImportMapFromProjectFiles/package-main-field/main-jsnext/package.json rename to test/getImportMapFromProjectFiles/package-main-field/main-jsnext/root/package.json diff --git a/test/getImportMapFromProjectFiles/package-main-field/main-relative/main-relative.test.js b/test/getImportMapFromProjectFiles/package-main-field/main-relative/main-relative.test.js index 75c6c93e..f0b83b7a 100644 --- a/test/getImportMapFromProjectFiles/package-main-field/main-relative/main-relative.test.js +++ b/test/getImportMapFromProjectFiles/package-main-field/main-relative/main-relative.test.js @@ -2,15 +2,16 @@ import { assert } from "@jsenv/assert" import { resolveUrl } from "@jsenv/util" import { getImportMapFromProjectFiles } from "@jsenv/node-module-import-map" -const testDirectoryUrl = resolveUrl("./", import.meta.url) +const testDirectoryUrl = resolveUrl("./root/", import.meta.url) const actual = await getImportMapFromProjectFiles({ projectDirectoryUrl: testDirectoryUrl, - packagesSelfReference: false, + jsFiles: false, }) const expected = { imports: { "main-relative": "./node_modules/main-relative/lib/index.js", + "root": "./index", }, scopes: {}, } diff --git a/test/getImportMapFromProjectFiles/package-main-field/main-directory-trailing/node_modules/main-folder-trailing/lib/index.js b/test/getImportMapFromProjectFiles/package-main-field/main-relative/root/node_modules/main-relative/lib/index.js similarity index 100% rename from test/getImportMapFromProjectFiles/package-main-field/main-directory-trailing/node_modules/main-folder-trailing/lib/index.js rename to test/getImportMapFromProjectFiles/package-main-field/main-relative/root/node_modules/main-relative/lib/index.js diff --git a/test/getImportMapFromProjectFiles/package-main-field/main-relative/node_modules/main-relative/package.json b/test/getImportMapFromProjectFiles/package-main-field/main-relative/root/node_modules/main-relative/package.json similarity index 100% rename from test/getImportMapFromProjectFiles/package-main-field/main-relative/node_modules/main-relative/package.json rename to test/getImportMapFromProjectFiles/package-main-field/main-relative/root/node_modules/main-relative/package.json diff --git a/test/getImportMapFromProjectFiles/package-main-field/main-relative/package.json b/test/getImportMapFromProjectFiles/package-main-field/main-relative/root/package.json similarity index 100% rename from test/getImportMapFromProjectFiles/package-main-field/main-relative/package.json rename to test/getImportMapFromProjectFiles/package-main-field/main-relative/root/package.json diff --git a/test/getImportMapFromProjectFiles/package-main-field/main-undefined/main-undefined.test.js b/test/getImportMapFromProjectFiles/package-main-field/main-undefined/main-undefined.test.js index 8b00db94..7fac4da8 100644 --- a/test/getImportMapFromProjectFiles/package-main-field/main-undefined/main-undefined.test.js +++ b/test/getImportMapFromProjectFiles/package-main-field/main-undefined/main-undefined.test.js @@ -2,15 +2,16 @@ import { assert } from "@jsenv/assert" import { resolveUrl } from "@jsenv/util" import { getImportMapFromProjectFiles } from "@jsenv/node-module-import-map" -const testDirectoryUrl = resolveUrl("./", import.meta.url) +const testDirectoryUrl = resolveUrl("./root/", import.meta.url) const actual = await getImportMapFromProjectFiles({ projectDirectoryUrl: testDirectoryUrl, - packagesSelfReference: false, + jsFiles: false, }) const expected = { imports: { "main-undefined": "./node_modules/main-undefined/index.js", + "root": "./index", }, scopes: {}, } diff --git a/test/getImportMapFromProjectFiles/package-main-field/main-directory/node_modules/main-directory/lib/index.js b/test/getImportMapFromProjectFiles/package-main-field/main-undefined/root/node_modules/main-undefined/index.js similarity index 100% rename from test/getImportMapFromProjectFiles/package-main-field/main-directory/node_modules/main-directory/lib/index.js rename to test/getImportMapFromProjectFiles/package-main-field/main-undefined/root/node_modules/main-undefined/index.js diff --git a/test/getImportMapFromProjectFiles/package-main-field/main-undefined/node_modules/main-undefined/package.json b/test/getImportMapFromProjectFiles/package-main-field/main-undefined/root/node_modules/main-undefined/package.json similarity index 100% rename from test/getImportMapFromProjectFiles/package-main-field/main-undefined/node_modules/main-undefined/package.json rename to test/getImportMapFromProjectFiles/package-main-field/main-undefined/root/node_modules/main-undefined/package.json diff --git a/test/getImportMapFromProjectFiles/package-main-field/main-undefined/package.json b/test/getImportMapFromProjectFiles/package-main-field/main-undefined/root/package.json similarity index 100% rename from test/getImportMapFromProjectFiles/package-main-field/main-undefined/package.json rename to test/getImportMapFromProjectFiles/package-main-field/main-undefined/root/package.json diff --git a/test/getImportMapFromProjectFiles/package-main-field/main-without-extension/main-without-extension.test.js b/test/getImportMapFromProjectFiles/package-main-field/main-without-extension/main-without-extension.test.js index 28264ee8..76569743 100644 --- a/test/getImportMapFromProjectFiles/package-main-field/main-without-extension/main-without-extension.test.js +++ b/test/getImportMapFromProjectFiles/package-main-field/main-without-extension/main-without-extension.test.js @@ -6,11 +6,12 @@ const testDirectoryUrl = resolveUrl("./root/", import.meta.url) const actual = await getImportMapFromProjectFiles({ projectDirectoryUrl: testDirectoryUrl, - packagesSelfReference: false, + jsFiles: false, }) const expected = { imports: { "main-without-extension": "./node_modules/main-without-extension/file.js", + "root": "./index", }, scopes: {}, } diff --git a/test/getImportMapFromProjectFiles/self-import/self-import-1/self-import.test.js b/test/getImportMapFromProjectFiles/self-import/self-import-1/self-import.test.js index fff01f28..dbe0aa61 100644 --- a/test/getImportMapFromProjectFiles/self-import/self-import-1/self-import.test.js +++ b/test/getImportMapFromProjectFiles/self-import/self-import-1/self-import.test.js @@ -9,8 +9,7 @@ const actual = await getImportMapFromProjectFiles({ }) const expected = { imports: { - "root/": "./", - "root": "./index.js", + root: "./index.js", }, scopes: {}, } diff --git a/test/getImportMapFromProjectFiles/self-import/self-import-2/node_modules/foo/index.js b/test/getImportMapFromProjectFiles/self-import/self-import-2/node_modules/foo/index.js deleted file mode 100644 index e69de29b..00000000 diff --git a/test/getImportMapFromProjectFiles/self-import/self-import-2/node_modules/foo/package.json b/test/getImportMapFromProjectFiles/self-import/self-import-2/node_modules/foo/package.json deleted file mode 100644 index fb4eeaff..00000000 --- a/test/getImportMapFromProjectFiles/self-import/self-import-2/node_modules/foo/package.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "name": "foo" -} \ No newline at end of file diff --git a/test/getImportMapFromProjectFiles/package-main-field/main-relative/node_modules/main-relative/lib/index.js b/test/getImportMapFromProjectFiles/self-import/self-import-2/root/index.js similarity index 100% rename from test/getImportMapFromProjectFiles/package-main-field/main-relative/node_modules/main-relative/lib/index.js rename to test/getImportMapFromProjectFiles/self-import/self-import-2/root/index.js diff --git a/test/getImportMapFromProjectFiles/package-main-field/main-undefined/node_modules/main-undefined/index.js b/test/getImportMapFromProjectFiles/self-import/self-import-2/root/node_modules/foo/index.js similarity index 100% rename from test/getImportMapFromProjectFiles/package-main-field/main-undefined/node_modules/main-undefined/index.js rename to test/getImportMapFromProjectFiles/self-import/self-import-2/root/node_modules/foo/index.js diff --git a/test/getImportMapFromProjectFiles/self-import/self-import-2/root/node_modules/foo/package.json b/test/getImportMapFromProjectFiles/self-import/self-import-2/root/node_modules/foo/package.json new file mode 100644 index 00000000..3d2e63ca --- /dev/null +++ b/test/getImportMapFromProjectFiles/self-import/self-import-2/root/node_modules/foo/package.json @@ -0,0 +1,6 @@ +{ + "name": "foo", + "exports": { + "./": "./" + } +} \ No newline at end of file diff --git a/test/getImportMapFromProjectFiles/self-import/self-import-2/package.json b/test/getImportMapFromProjectFiles/self-import/self-import-2/root/package.json similarity index 100% rename from test/getImportMapFromProjectFiles/self-import/self-import-2/package.json rename to test/getImportMapFromProjectFiles/self-import/self-import-2/root/package.json diff --git a/test/getImportMapFromProjectFiles/self-import/self-import-2/self-import-2.test.js b/test/getImportMapFromProjectFiles/self-import/self-import-2/self-import-2.test.js index dae1a861..470b7279 100644 --- a/test/getImportMapFromProjectFiles/self-import/self-import-2/self-import-2.test.js +++ b/test/getImportMapFromProjectFiles/self-import/self-import-2/self-import-2.test.js @@ -2,21 +2,17 @@ import { assert } from "@jsenv/assert" import { resolveUrl } from "@jsenv/util" import { getImportMapFromProjectFiles } from "@jsenv/node-module-import-map" -const testDirectoryUrl = resolveUrl("./", import.meta.url) +const testDirectoryUrl = resolveUrl("./root/", import.meta.url) const actual = await getImportMapFromProjectFiles({ projectDirectoryUrl: testDirectoryUrl, }) const expected = { imports: { - "root/": "./", + "foo/": "./node_modules/foo/", "root": "./index.js", "foo": "./node_modules/foo/index.js", }, - scopes: { - "./node_modules/foo/": { - "foo/": "./node_modules/foo/", - }, - }, + scopes: {}, } assert({ actual, expected }) diff --git a/test/getImportMapFromProjectFiles/self-import/self-import-4/index.js b/test/getImportMapFromProjectFiles/self-import/self-import-4/index.js deleted file mode 100644 index e69de29b..00000000 diff --git a/test/getImportMapFromProjectFiles/self-import/self-import-4/node_modules/@jsenv/core/package.json b/test/getImportMapFromProjectFiles/self-import/self-import-4/node_modules/@jsenv/core/package.json deleted file mode 100644 index 1f78ab81..00000000 --- a/test/getImportMapFromProjectFiles/self-import/self-import-4/node_modules/@jsenv/core/package.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "name": "@jsenv/core" -} \ No newline at end of file diff --git a/test/getImportMapFromProjectFiles/self-import/self-import-2/index.js b/test/getImportMapFromProjectFiles/self-import/self-import-4/root/index.js similarity index 100% rename from test/getImportMapFromProjectFiles/self-import/self-import-2/index.js rename to test/getImportMapFromProjectFiles/self-import/self-import-4/root/index.js diff --git a/test/getImportMapFromProjectFiles/self-import/self-import-5/node_modules/@jsenv/core/package.json b/test/getImportMapFromProjectFiles/self-import/self-import-4/root/node_modules/@jsenv/core/package.json similarity index 100% rename from test/getImportMapFromProjectFiles/self-import/self-import-5/node_modules/@jsenv/core/package.json rename to test/getImportMapFromProjectFiles/self-import/self-import-4/root/node_modules/@jsenv/core/package.json diff --git a/test/getImportMapFromProjectFiles/self-import/self-import-4/package.json b/test/getImportMapFromProjectFiles/self-import/self-import-4/root/package.json similarity index 73% rename from test/getImportMapFromProjectFiles/self-import/self-import-4/package.json rename to test/getImportMapFromProjectFiles/self-import/self-import-4/root/package.json index fc246840..eb5c9977 100644 --- a/test/getImportMapFromProjectFiles/self-import/self-import-4/package.json +++ b/test/getImportMapFromProjectFiles/self-import/self-import-4/root/package.json @@ -3,5 +3,8 @@ "type": "module", "devDependencies": { "@jsenv/core": "*" + }, + "exports": { + "./": "./" } } diff --git a/test/getImportMapFromProjectFiles/self-import/self-import-4/self-import-4.test.js b/test/getImportMapFromProjectFiles/self-import/self-import-4/self-import-4.test.js index acd8d57f..256bd639 100644 --- a/test/getImportMapFromProjectFiles/self-import/self-import-4/self-import-4.test.js +++ b/test/getImportMapFromProjectFiles/self-import/self-import-4/self-import-4.test.js @@ -2,11 +2,11 @@ import { assert } from "@jsenv/assert" import { resolveUrl } from "@jsenv/util" import { getImportMapFromProjectFiles } from "@jsenv/node-module-import-map" -const testDirectoryUrl = resolveUrl("./", import.meta.url) +const testDirectoryUrl = resolveUrl("./root/", import.meta.url) const actual = await getImportMapFromProjectFiles({ projectDirectoryUrl: testDirectoryUrl, - projectPackageDevDependenciesIncluded: true, + dev: true, }) const expected = { imports: { diff --git a/test/getImportMapFromProjectFiles/self-import/self-import-5/root/node_modules/@jsenv/core/package.json b/test/getImportMapFromProjectFiles/self-import/self-import-5/root/node_modules/@jsenv/core/package.json new file mode 100644 index 00000000..e3b88fbd --- /dev/null +++ b/test/getImportMapFromProjectFiles/self-import/self-import-5/root/node_modules/@jsenv/core/package.json @@ -0,0 +1,6 @@ +{ + "name": "@jsenv/core", + "exports": { + "./": "./" + } +} \ No newline at end of file diff --git a/test/getImportMapFromProjectFiles/self-import/self-import-5/package.json b/test/getImportMapFromProjectFiles/self-import/self-import-5/root/package.json similarity index 73% rename from test/getImportMapFromProjectFiles/self-import/self-import-5/package.json rename to test/getImportMapFromProjectFiles/self-import/self-import-5/root/package.json index fc246840..eb5c9977 100644 --- a/test/getImportMapFromProjectFiles/self-import/self-import-5/package.json +++ b/test/getImportMapFromProjectFiles/self-import/self-import-5/root/package.json @@ -3,5 +3,8 @@ "type": "module", "devDependencies": { "@jsenv/core": "*" + }, + "exports": { + "./": "./" } } diff --git a/test/getImportMapFromProjectFiles/self-import/self-import-5/self-import-5.test.js b/test/getImportMapFromProjectFiles/self-import/self-import-5/self-import-5.test.js index 82d1e9a9..4ff34858 100644 --- a/test/getImportMapFromProjectFiles/self-import/self-import-5/self-import-5.test.js +++ b/test/getImportMapFromProjectFiles/self-import/self-import-5/self-import-5.test.js @@ -2,11 +2,11 @@ import { assert } from "@jsenv/assert" import { resolveUrl } from "@jsenv/util" import { getImportMapFromProjectFiles } from "@jsenv/node-module-import-map" -const testDirectoryUrl = resolveUrl("./", import.meta.url) +const testDirectoryUrl = resolveUrl("./root/", import.meta.url) const actual = await getImportMapFromProjectFiles({ projectDirectoryUrl: testDirectoryUrl, - projectPackageDevDependenciesIncluded: true, + dev: true, }) const expected = { imports: { diff --git a/test/getImportMapFromProjectFiles/self-import/self-import-6/self-import-6.test.js b/test/getImportMapFromProjectFiles/self-import/self-import-6/self-import-6.test.js index 747f403e..a2584b54 100644 --- a/test/getImportMapFromProjectFiles/self-import/self-import-6/self-import-6.test.js +++ b/test/getImportMapFromProjectFiles/self-import/self-import-6/self-import-6.test.js @@ -13,13 +13,11 @@ const expected = { "@jsenv/core/conflict": "./root.js", "@jsenv/core/rootonly": "./rootonly.js", "@jsenv/core/deponly": "./node_modules/@jsenv/core/deponly.js", - "@jsenv/core/": "./", "@jsenv/core": "./index.js", }, scopes: { "./node_modules/@jsenv/core/": { "@jsenv/core/conflict": "./node_modules/@jsenv/core/dep.js", - "@jsenv/core/": "./node_modules/@jsenv/core/", "@jsenv/core": "./node_modules/@jsenv/core/maindep.js", }, "./root/": { From e0ab74ec749fa84217b7c4496e2fded5c7c5f31e Mon Sep 17 00:00:00 2001 From: Damien Maillard Date: Thu, 11 Mar 2021 14:55:27 +0100 Subject: [PATCH 20/36] Prepare testing js files mapping generation --- .../from-js/getImportMapFromJsFiles.js | 76 ++++------------- .../getImportMapFromPackageFiles.js | 3 +- .../from-package/node-module-resolution.js | 2 +- .../from-package/resolvePackageMain.js | 20 ++++- src/internal/memoizeAsyncFunction.js | 81 +++++++++++++++++++ src/internal/memoizeAsyncFunctionByUrl.js | 32 -------- .../extensionless-js/extensionless-js.test.js | 2 + 7 files changed, 119 insertions(+), 97 deletions(-) create mode 100644 src/internal/memoizeAsyncFunction.js delete mode 100644 src/internal/memoizeAsyncFunctionByUrl.js diff --git a/src/internal/from-js/getImportMapFromJsFiles.js b/src/internal/from-js/getImportMapFromJsFiles.js index 78d78b0c..12e543bf 100644 --- a/src/internal/from-js/getImportMapFromJsFiles.js +++ b/src/internal/from-js/getImportMapFromJsFiles.js @@ -23,9 +23,12 @@ si c'est pas un bare specifier et que le fichier est pas trouvé */ import { createLogger, createDetailedMessage } from "@jsenv/logger" -import { readFile, resolveUrl, urlToExtension } from "@jsenv/util" +import { readFile, urlToExtension } from "@jsenv/util" import { resolveImport } from "@jsenv/import-map" -import { memoizeAsyncFunctionByUrl } from "../memoizeAsyncFunctionByUrl.js" +import { + memoizeAsyncFunctionByUrl, + memoizeAsyncFunctionBySpecifierAndImporter, +} from "../memoizeAsyncFunction.js" import { parseSpecifiersFromFile } from "./parseSpecifiersFromFile.js" import { showSource } from "./showSource.js" @@ -36,12 +39,10 @@ export const getImportMapFromJsFiles = async ({ importMap, projectDirectoryUrl, magicExtensions = [".js", ".jsx", ".ts", ".tsx", ".node", ".json"], - runtime, - packagePreferences, }) => { const logger = createLogger({ logLevel }) - const visitFile = async (specifier, importer, { importedIn }) => { + const visitFile = async (specifier, importer, { importedBy }) => { let fileUrl let bareSpecifier = false @@ -76,7 +77,7 @@ export const getImportMapFromJsFiles = async ({ logger.warn( formatFileNotFoundLog({ specifier, - importedIn, + importedBy, magicExtensions, }), ) @@ -89,8 +90,8 @@ export const getImportMapFromJsFiles = async ({ await Promise.all( Object.keys(specifiers).map(async (specifier) => { const specifierInfo = specifiers[specifier] - await visitFile(specifier, fileUrl, { - importedIn: showSource({ + await visitFileMemoized(specifier, fileUrl, { + importedBy: showSource({ url: fileUrl, line: specifierInfo.line, column: specifierInfo.column, @@ -100,67 +101,22 @@ export const getImportMapFromJsFiles = async ({ }), ) } - const visitFileMemoized = memoizeAsyncFunctionByUrl(visitFile) + const visitFileMemoized = memoizeAsyncFunctionBySpecifierAndImporter(visitFile) const readFileContent = memoizeAsyncFunctionByUrl((fileUrl) => { return readFile(fileUrl, { as: "string" }) }) - const rootPackageFileUrl = resolveUrl("package.json", projectDirectoryUrl) - const rootPackageObject = await readFileContent(rootPackageFileUrl) - const rootMainInfo = mainFromPackageObject({ - packageObject: rootPackageObject, - packageFileUrl: rootPackageFileUrl, - runtime, - packagePreferences, + // TODO: it's not ./ but the packagename + // found in package.json to get the main file + await visitFileMemoized("./", projectDirectoryUrl, { + importedBy: `getImportMapFromJsFiles`, }) - await visitFileMemoized(rootMainInfo.specifier, rootPackageFileUrl, { - importedIn: rootMainInfo.importedIn, - }) -} - -const mainFromPackageObject = ({ packageObject, packageFileUrl, runtime }) => { - // idéalement on lirait aussi package.exports - // pour y trouver le point d'entrée principal - // soit ".", soit la chaine directe - - if ("module" in packageObject) { - return { - specifier: packageObject.module, - importedIn: `${packageFileUrl}#module`, - } - } - - if ("jsnext:main" in packageObject) { - return { - specifier: packageObject["jsnext:main"], - importedIn: `${packageFileUrl}#jsnext:main`, - } - } - - if (runtime === "browser" && "browser" in packageObject) { - return { - specifier: packageObject.browser, - importedIn: `${packageFileUrl}#browser`, - } - } - - if ("main" in packageObject) { - return { - specifier: packageObject.main, - importedIn: `${packageFileUrl}#main`, - } - } - - return { - specifier: "index", - importedIn: `${packageFileUrl}#default`, - } } -const formatFileNotFoundLog = ({ specifier, expectedUrl, magicExtensions, importedIn }) => { +const formatFileNotFoundLog = ({ specifier, expectedUrl, magicExtensions, importedBy }) => { return createDetailedMessage(`Cannot find file for "${specifier}"`, { - "imported in": importedIn, + "imported by": importedBy, "file url": expectedUrl, ...(urlToExtension(expectedUrl) === "" ? { ["extensions tried"]: magicExtensions.join(`,`) } diff --git a/src/internal/from-package/getImportMapFromPackageFiles.js b/src/internal/from-package/getImportMapFromPackageFiles.js index 3c65b857..954bf017 100644 --- a/src/internal/from-package/getImportMapFromPackageFiles.js +++ b/src/internal/from-package/getImportMapFromPackageFiles.js @@ -307,9 +307,10 @@ export const getImportMapFromPackageFiles = async ({ }, }) => { const mainFileUrl = await resolvePackageMain({ + logger, + packagesExportsPreference, packageFileUrl, packageJsonObject, - logger, }) // it's possible to have no main diff --git a/src/internal/from-package/node-module-resolution.js b/src/internal/from-package/node-module-resolution.js index 10649567..17b7e0dd 100644 --- a/src/internal/from-package/node-module-resolution.js +++ b/src/internal/from-package/node-module-resolution.js @@ -1,6 +1,6 @@ import { firstOperationMatching } from "@jsenv/cancellation" import { urlToRelativeUrl, resolveUrl } from "@jsenv/util" -import { memoizeAsyncFunctionByUrl } from "../memoizeAsyncFunctionByUrl.js" +import { memoizeAsyncFunctionByUrl } from "../memoizeAsyncFunction.js" import { readPackageFile, PACKAGE_NOT_FOUND, PACKAGE_WITH_SYNTAX_ERROR } from "./readPackageFile.js" export const createFindNodeModulePackage = (packagesManualOverrides) => { diff --git a/src/internal/from-package/resolvePackageMain.js b/src/internal/from-package/resolvePackageMain.js index 2f30ed1d..d9f1caf4 100644 --- a/src/internal/from-package/resolvePackageMain.js +++ b/src/internal/from-package/resolvePackageMain.js @@ -4,8 +4,13 @@ import { resolveFile } from "./resolveFile.js" const magicExtensions = ["js", "json", "node"] -export const resolvePackageMain = ({ logger, packageFileUrl, packageJsonObject }) => { - if ("module" in packageJsonObject) { +export const resolvePackageMain = ({ + logger, + packagesExportsPreference, + packageFileUrl, + packageJsonObject, +}) => { + if (packagesExportsPreference.includes("import") && "module" in packageJsonObject) { return resolveMainFile({ logger, packageFileUrl, @@ -14,7 +19,7 @@ export const resolvePackageMain = ({ logger, packageFileUrl, packageJsonObject } }) } - if ("jsnext:main" in packageJsonObject) { + if (packagesExportsPreference.includes("import") && "jsnext:main" in packageJsonObject) { return resolveMainFile({ logger, packageFileUrl, @@ -23,6 +28,15 @@ export const resolvePackageMain = ({ logger, packageFileUrl, packageJsonObject } }) } + if (packagesExportsPreference.includes("browser") && "browser" in packageJsonObject) { + return resolveMainFile({ + logger, + packageFileUrl, + packageMainFieldName: "browser", + packageMainFieldValue: packageJsonObject.browser, + }) + } + if ("main" in packageJsonObject) { return resolveMainFile({ logger, diff --git a/src/internal/memoizeAsyncFunction.js b/src/internal/memoizeAsyncFunction.js new file mode 100644 index 00000000..5e5a46bc --- /dev/null +++ b/src/internal/memoizeAsyncFunction.js @@ -0,0 +1,81 @@ +export const memoizeAsyncFunctionByUrl = (fn) => { + const cache = {} + return memoizeAsyncFunction(fn, { + getMemoryEntryFromArguments: ([url]) => { + return { + get: () => { + return cache[url] + }, + set: (promise) => { + cache[url] = promise + }, + delete: () => { + delete cache[url] + }, + } + }, + }) +} + +export const memoizeAsyncFunctionBySpecifierAndImporter = (fn) => { + const importerCache = {} + return memoizeAsyncFunction(fn, { + getMemoryEntryFromArguments: ([specifier, importer]) => { + return { + get: () => { + const specifierCacheForImporter = importerCache[importer] + return specifierCacheForImporter ? specifierCacheForImporter[specifier] : null + }, + set: (promise) => { + const specifierCacheForImporter = importerCache[importer] + if (specifierCacheForImporter) { + specifierCacheForImporter[specifier] = promise + } else { + importerCache[importer] = { + [specifier]: promise, + } + } + }, + delete: () => { + const specifierCacheForImporter = importerCache[importer] + if (specifierCacheForImporter) { + delete specifierCacheForImporter[specifier] + } + }, + } + }, + }) +} + +const memoizeAsyncFunction = (fn, { getMemoryEntryFromArguments }) => { + return async (...args) => { + const memoryEntry = getMemoryEntryFromArguments(args) + const promiseFromMemory = memoryEntry.get() + if (promiseFromMemory) { + return promiseFromMemory + } + let _resolve + let _reject + const promise = new Promise((resolve, reject) => { + _resolve = resolve + _reject = reject + }) + memoryEntry.set(promise) + let value + let error + try { + value = fn(...args) + error = false + } catch (e) { + value = e + error = true + memoryEntry.delete() + } + if (error) { + _reject(error) + } else { + _resolve(value) + } + return promise + } +} diff --git a/src/internal/memoizeAsyncFunctionByUrl.js b/src/internal/memoizeAsyncFunctionByUrl.js deleted file mode 100644 index 82e7a555..00000000 --- a/src/internal/memoizeAsyncFunctionByUrl.js +++ /dev/null @@ -1,32 +0,0 @@ -export const memoizeAsyncFunctionByUrl = (fn) => { - const cache = {} - return async (url, ...args) => { - const promiseFromCache = cache[url] - if (promiseFromCache) { - return promiseFromCache - } - let _resolve - let _reject - const promise = new Promise((resolve, reject) => { - _resolve = resolve - _reject = reject - }) - cache[url] = promise - let value - let error - try { - value = fn(url, ...args) - error = false - } catch (e) { - value = e - error = true - delete cache[url] - } - if (error) { - _reject(error) - } else { - _resolve(value) - } - return promise - } -} diff --git a/test/getImportMapFromProjectFiles/from-js/extensionless-js/extensionless-js.test.js b/test/getImportMapFromProjectFiles/from-js/extensionless-js/extensionless-js.test.js index 15ae240f..cd1603ed 100644 --- a/test/getImportMapFromProjectFiles/from-js/extensionless-js/extensionless-js.test.js +++ b/test/getImportMapFromProjectFiles/from-js/extensionless-js/extensionless-js.test.js @@ -6,9 +6,11 @@ const testDirectoryUrl = resolveUrl("./root/", import.meta.url) const actual = await getImportMapFromProjectFiles({ projectDirectoryUrl: testDirectoryUrl, + jsFiles: true, }) const expected = { imports: { + file: "./file.js", root: "./index.js", }, scopes: {}, From 742875723b1a093526a4d9c61be201d446f56bcf Mon Sep 17 00:00:00 2001 From: Damien Maillard Date: Thu, 11 Mar 2021 17:08:01 +0100 Subject: [PATCH 21/36] auto mapping extensionless specifier working --- src/getImportMapFromProjectFiles.js | 2 +- .../from-js/getImportMapFromJsFiles.js | 202 +++++++++++++++--- .../from-js/parseSpecifiersFromFile.js | 4 +- src/internal/from-js/showSource.js | 10 +- .../from-package/resolvePackageMain.js | 6 +- .../{from-package => }/resolveFile.js | 14 +- .../extensionless-js/extensionless-js.test.js | 4 +- 7 files changed, 193 insertions(+), 49 deletions(-) rename src/internal/{from-package => }/resolveFile.js (75%) diff --git a/src/getImportMapFromProjectFiles.js b/src/getImportMapFromProjectFiles.js index 59e81d10..73126f73 100644 --- a/src/getImportMapFromProjectFiles.js +++ b/src/getImportMapFromProjectFiles.js @@ -40,7 +40,7 @@ export const getImportMapFromProjectFiles = async ({ : {} importMapFromJsFiles = sortImportMap(importMapFromJsFiles) - return composeTwoImportMaps(importMapFromPackageFiles, importMapFromJsFiles) + return sortImportMap(composeTwoImportMaps(importMapFromPackageFiles, importMapFromJsFiles)) } const runtimeExportsPreferences = { diff --git a/src/internal/from-js/getImportMapFromJsFiles.js b/src/internal/from-js/getImportMapFromJsFiles.js index 12e543bf..2b405fca 100644 --- a/src/internal/from-js/getImportMapFromJsFiles.js +++ b/src/internal/from-js/getImportMapFromJsFiles.js @@ -23,14 +23,15 @@ si c'est pas un bare specifier et que le fichier est pas trouvé */ import { createLogger, createDetailedMessage } from "@jsenv/logger" -import { readFile, urlToExtension } from "@jsenv/util" -import { resolveImport } from "@jsenv/import-map" +import { resolveUrl, readFile, urlToExtension, urlToRelativeUrl } from "@jsenv/util" +import { normalizeImportMap, resolveImport } from "@jsenv/import-map" import { memoizeAsyncFunctionByUrl, memoizeAsyncFunctionBySpecifierAndImporter, } from "../memoizeAsyncFunction.js" import { parseSpecifiersFromFile } from "./parseSpecifiersFromFile.js" import { showSource } from "./showSource.js" +import { resolveFile } from "../resolveFile.js" const BARE_SPECIFIER_ERROR = {} @@ -41,10 +42,26 @@ export const getImportMapFromJsFiles = async ({ magicExtensions = [".js", ".jsx", ".ts", ".tsx", ".node", ".json"], }) => { const logger = createLogger({ logLevel }) + const projectPackageFileUrl = resolveUrl("./package.json", projectDirectoryUrl) + + importMap = normalizeImportMap(importMap, projectDirectoryUrl) + + const imports = {} + const scopes = {} + const addMapping = ({ scope, from, to }) => { + if (scope) { + scopes[scope] = { + ...(scopes[scope] || {}), + [from]: to, + } + } else { + imports[from] = to + } + } const visitFile = async (specifier, importer, { importedBy }) => { let fileUrl - let bareSpecifier = false + let gotBareSpecifierError = false try { fileUrl = resolveImport({ @@ -58,41 +75,58 @@ export const getImportMapFromJsFiles = async ({ if (e !== BARE_SPECIFIER_ERROR) { throw e } - bareSpecifier = true + gotBareSpecifierError = true } - // TODO: auto ajouter importer extension dans les magic extensions + const fileUrlOnFileSystem = await resolveFile(fileUrl, { + magicExtensions: magicExtensionWithImporterExtension(magicExtensions, importer), + }) - if (bareSpecifier) { - // - s'il existe un fichier avec le meme nom - // -> suggerer un remapping et lajouter de force - // - si magic extension - // -> suggerer un remapping et l'ajouter de force - } else { - // - si magic extension - // -> suggerer un remapping et l'ajouter de force - } - - if (!fileUrl) { + if (!fileUrlOnFileSystem) { logger.warn( formatFileNotFoundLog({ specifier, importedBy, + fileUrl, magicExtensions, }), ) return } - const fileContent = await readFileContent(fileUrl) - const specifiers = await parseSpecifiersFromFile(fileUrl, { fileContent }) + const needsAutoMapping = fileUrlOnFileSystem !== fileUrl || gotBareSpecifierError + if (needsAutoMapping) { + const packageDirectoryUrl = packageDirectoryUrlFromUrl(fileUrl, projectDirectoryUrl) + const packageFileUrl = resolveUrl("package.json", packageDirectoryUrl) + const autoMapping = { + scope: + packageFileUrl === projectPackageFileUrl + ? undefined + : `./${urlToRelativeUrl(packageDirectoryUrl, projectDirectoryUrl)}`, + from: specifier, + to: `./${urlToRelativeUrl(fileUrlOnFileSystem, projectDirectoryUrl)}`, + } + addMapping(autoMapping) + logger.warn( + formatAutoMappingSpecifierWarning({ + specifier, + importedBy, + autoMapping, + closestPackageDirectoryUrl: packageDirectoryUrl, + closestPackageObject: await readFile(packageFileUrl, { as: "json" }), + }), + ) + } + + const fileContent = await readFileContent(fileUrlOnFileSystem) + const specifiers = await parseSpecifiersFromFile(fileUrlOnFileSystem, { fileContent }) await Promise.all( Object.keys(specifiers).map(async (specifier) => { const specifierInfo = specifiers[specifier] - await visitFileMemoized(specifier, fileUrl, { + await visitFileMemoized(specifier, fileUrlOnFileSystem, { importedBy: showSource({ - url: fileUrl, + url: fileUrlOnFileSystem, line: specifierInfo.line, column: specifierInfo.column, source: fileContent, @@ -107,19 +141,129 @@ export const getImportMapFromJsFiles = async ({ return readFile(fileUrl, { as: "string" }) }) - // TODO: it's not ./ but the packagename - // found in package.json to get the main file - await visitFileMemoized("./", projectDirectoryUrl, { - importedBy: `getImportMapFromJsFiles`, + const projectPackageObject = await readFile(projectPackageFileUrl, { as: "json" }) + await visitFileMemoized(projectPackageObject.name, projectPackageFileUrl, { + importedBy: projectPackageObject.exports + ? `${projectPackageFileUrl}#exports` + : `${projectPackageFileUrl}`, }) + + return { imports, scopes } } -const formatFileNotFoundLog = ({ specifier, expectedUrl, magicExtensions, importedBy }) => { +const packageDirectoryUrlFromUrl = (url, projectDirectoryUrl) => { + const relativeUrl = urlToRelativeUrl(url, projectDirectoryUrl) + + const lastNodeModulesDirectoryStartIndex = relativeUrl.lastIndexOf("node_modules/") + if (lastNodeModulesDirectoryStartIndex === -1) { + return projectDirectoryUrl + } + + const lastNodeModulesDirectoryEndIndex = + lastNodeModulesDirectoryStartIndex + `node_modules/`.length + + const beforeNodeModulesLastDirectory = relativeUrl.slice(0, lastNodeModulesDirectoryEndIndex) + const afterLastNodeModulesDirectory = relativeUrl.slice(lastNodeModulesDirectoryEndIndex) + const remainingDirectories = afterLastNodeModulesDirectory.split("/") + + if (afterLastNodeModulesDirectory[0] === "@") { + // scoped package + return `${projectDirectoryUrl}${beforeNodeModulesLastDirectory}${remainingDirectories + .slice(0, 2) + .join("/")}` + } + return `${projectDirectoryUrl}${beforeNodeModulesLastDirectory}${remainingDirectories[0]}/` +} + +const magicExtensionWithImporterExtension = (magicExtensions, importer) => { + const importerExtension = urlToExtension(importer) + const magicExtensionsWithoutImporterExtension = magicExtensions.filter( + (ext) => ext !== importerExtension, + ) + return [importerExtension, ...magicExtensionsWithoutImporterExtension] +} + +const formatFileNotFoundLog = ({ specifier, importedBy, fileUrl, magicExtensions }) => { return createDetailedMessage(`Cannot find file for "${specifier}"`, { "imported by": importedBy, - "file url": expectedUrl, - ...(urlToExtension(expectedUrl) === "" - ? { ["extensions tried"]: magicExtensions.join(`,`) } - : {}), + "file url": fileUrl, + ...(urlToExtension(fileUrl) === "" ? { ["extensions tried"]: magicExtensions.join(`, `) } : {}), }) } + +const formatAutoMappingSpecifierWarning = ({ + importedBy, + autoMapping, + closestPackageDirectoryUrl, + closestPackageObject, +}) => { + return ` +${createDetailedMessage(`Auto mapping ${autoMapping.from} to ${autoMapping.to}.`, { + "specifier origin": importedBy, + "suggestion": decideAutoMappingSuggestion({ + autoMapping, + closestPackageDirectoryUrl, + closestPackageObject, + }), +})} +` +} + +const decideAutoMappingSuggestion = ({ + autoMapping, + closestPackageDirectoryUrl, + closestPackageObject, +}) => { + if (typeof closestPackageObject.importmap === "string") { + const packageImportmapFileUrl = resolveUrl( + closestPackageObject.importmap, + closestPackageDirectoryUrl, + ) + + return `Add +${mappingToImportmapString(autoMapping)} +into ${packageImportmapFileUrl}.` + } + + return `Add +${mappingToExportsFieldString(autoMapping)} +into ${closestPackageDirectoryUrl}package.json.` +} + +const mappingToImportmapString = ({ scope, from, to }) => { + if (scope) { + return JSON.stringify( + { + scopes: { + [scope]: { + [from]: to, + }, + }, + }, + null, + " ", + ) + } + + return JSON.stringify( + { + imports: { + [from]: to, + }, + }, + null, + " ", + ) +} + +const mappingToExportsFieldString = ({ from, to }) => { + return JSON.stringify( + { + exports: { + [from]: to, + }, + }, + null, + " ", + ) +} diff --git a/src/internal/from-js/parseSpecifiersFromFile.js b/src/internal/from-js/parseSpecifiersFromFile.js index c001e2b9..9b722e3e 100644 --- a/src/internal/from-js/parseSpecifiersFromFile.js +++ b/src/internal/from-js/parseSpecifiersFromFile.js @@ -44,8 +44,8 @@ export const parseSpecifiersFromFile = async ( const addSpecifier = ({ path, type }) => { const specifier = path.node.value specifiers[specifier] = { - // TODO: pass path.node.range as well, or dieally something like - // line + column + line: path.node.loc.start.line, + column: path.node.loc.start.column, type, } } diff --git a/src/internal/from-js/showSource.js b/src/internal/from-js/showSource.js index 7e0b47a3..7df0a607 100644 --- a/src/internal/from-js/showSource.js +++ b/src/internal/from-js/showSource.js @@ -86,11 +86,11 @@ const showSourceLocation = ( if (column === undefined) { return `${mark(">")} ${lineFormatted}` } - const spacing = stringToSpaces( - `${asideSource} ${lineSourceTruncated.slice(0, column - columnRange.start - 1)}`, - ) - return `${mark(">")} ${lineFormatted} - ${spacing}${mark("^")}` + const lineSourceUntilColumn = lineSourceTruncated.slice(0, column - columnRange.start) + const spacing = stringToSpaces(lineSourceUntilColumn) + const mainLineFormatted = `${mark(">")} ${lineFormatted} + ${" ".repeat(lineNumberWidth)} ${aside("|")}${spacing}${mark("^")}` + return mainLineFormatted } return ` ${lineFormatted}` }).join(` diff --git a/src/internal/from-package/resolvePackageMain.js b/src/internal/from-package/resolvePackageMain.js index d9f1caf4..f2590a3e 100644 --- a/src/internal/from-package/resolvePackageMain.js +++ b/src/internal/from-package/resolvePackageMain.js @@ -1,8 +1,8 @@ import { createDetailedMessage } from "@jsenv/logger" import { resolveUrl, urlToFileSystemPath, urlToExtension } from "@jsenv/util" -import { resolveFile } from "./resolveFile.js" +import { resolveFile } from "../resolveFile.js" -const magicExtensions = ["js", "json", "node"] +const magicExtensions = [".js", ".json", ".node"] export const resolvePackageMain = ({ logger, @@ -118,6 +118,6 @@ const formatFileNotFoundLog = ({ specifier, importedIn, fileUrl, magicExtensions return createDetailedMessage(`Cannot find file for "${specifier}"`, { "imported in": importedIn, "file url": fileUrl, - ...(urlToExtension(fileUrl) === "" ? { ["extensions tried"]: magicExtensions.join(`,`) } : {}), + ...(urlToExtension(fileUrl) === "" ? { ["extensions tried"]: magicExtensions.join(`, `) } : {}), }) } diff --git a/src/internal/from-package/resolveFile.js b/src/internal/resolveFile.js similarity index 75% rename from src/internal/from-package/resolveFile.js rename to src/internal/resolveFile.js index e8b0f05f..bd0f021f 100644 --- a/src/internal/from-package/resolveFile.js +++ b/src/internal/resolveFile.js @@ -1,4 +1,4 @@ -import { resolveUrl, readFileSystemNodeStat, urlToBasename, urlToExtension } from "@jsenv/util" +import { resolveUrl, readFileSystemNodeStat, urlToFilename, urlToExtension } from "@jsenv/util" import { firstOperationMatching } from "@jsenv/cancellation" export const resolveFile = async (fileUrl, { magicExtensions }) => { @@ -19,7 +19,7 @@ export const resolveFile = async (fileUrl, { magicExtensions }) => { if (extensionLeadingToAFile === null) { return null } - return `${indexFileUrl}.${extensionLeadingToAFile}` + return `${indexFileUrl}${extensionLeadingToAFile}` } // file not found and it has an extension @@ -35,17 +35,17 @@ export const resolveFile = async (fileUrl, { magicExtensions }) => { } // magic extension worked - return `${fileUrl}.${extensionLeadingToAFile}` + return `${fileUrl}${extensionLeadingToAFile}` } const findExtensionLeadingToFile = async (fileUrl, magicExtensions) => { - const fileDirectoryUrl = resolveUrl("./", fileUrl) - const fileBasename = urlToBasename(fileUrl) + const urlDirectoryUrl = resolveUrl("./", fileUrl) + const urlFilename = urlToFilename(fileUrl) const extensionLeadingToFile = await firstOperationMatching({ array: magicExtensions, start: async (extensionCandidate) => { - const filePathCandidate = `${fileDirectoryUrl}/${fileBasename}.${extensionCandidate}` - const stats = await readFileSystemNodeStat(filePathCandidate, { nullIfNotFound: true }) + const urlCandidate = `${urlDirectoryUrl}${urlFilename}${extensionCandidate}` + const stats = await readFileSystemNodeStat(urlCandidate, { nullIfNotFound: true }) return stats && stats.isFile() ? extensionCandidate : null }, predicate: (extension) => Boolean(extension), diff --git a/test/getImportMapFromProjectFiles/from-js/extensionless-js/extensionless-js.test.js b/test/getImportMapFromProjectFiles/from-js/extensionless-js/extensionless-js.test.js index cd1603ed..1b016334 100644 --- a/test/getImportMapFromProjectFiles/from-js/extensionless-js/extensionless-js.test.js +++ b/test/getImportMapFromProjectFiles/from-js/extensionless-js/extensionless-js.test.js @@ -10,8 +10,8 @@ const actual = await getImportMapFromProjectFiles({ }) const expected = { imports: { - file: "./file.js", - root: "./index.js", + "./file": "./file.js", + "root": "./index.js", }, scopes: {}, } From cce489cb186d870dfb1cf31d7ba8433c9fc482b0 Mon Sep 17 00:00:00 2001 From: Damien Maillard Date: Thu, 11 Mar 2021 17:49:18 +0100 Subject: [PATCH 22/36] Introduce removeUnusedMappings --- package.json | 2 +- src/getImportMapFromProjectFiles.js | 2 + .../from-js/getImportMapFromJsFiles.js | 83 ++++++++++++------- 3 files changed, 57 insertions(+), 30 deletions(-) diff --git a/package.json b/package.json index 974aec1d..0e60791c 100644 --- a/package.json +++ b/package.json @@ -46,7 +46,7 @@ "@babel/parser": "7.13.9", "@babel/traverse": "7.13.0", "@jsenv/cancellation": "2.0.3", - "@jsenv/import-map": "6.11.1", + "@jsenv/import-map": "6.12.0", "@jsenv/logger": "4.0.0", "@jsenv/util": "4.0.6" }, diff --git a/src/getImportMapFromProjectFiles.js b/src/getImportMapFromProjectFiles.js index 73126f73..4dfdca4b 100644 --- a/src/getImportMapFromProjectFiles.js +++ b/src/getImportMapFromProjectFiles.js @@ -9,6 +9,7 @@ export const getImportMapFromProjectFiles = async ({ moduleFormat = "esm", dev = false, jsFiles = false, + removeUnusedMappings = !dev, magicExtensions, ...rest }) => { @@ -32,6 +33,7 @@ export const getImportMapFromProjectFiles = async ({ ? await getImportMapFromJsFiles({ logLevel, importMap: importMapFromPackageFiles, + removeUnusedMappings, projectDirectoryUrl, magicExtensions, packagesExportsPreference, diff --git a/src/internal/from-js/getImportMapFromJsFiles.js b/src/internal/from-js/getImportMapFromJsFiles.js index 2b405fca..7b0e1328 100644 --- a/src/internal/from-js/getImportMapFromJsFiles.js +++ b/src/internal/from-js/getImportMapFromJsFiles.js @@ -1,25 +1,5 @@ /* -IL SERAIT BIEN DE CONNAITRE TOUTES LES IMPORTMAPS -POUR PAS DIRE DE BETISES: -- que ce soit parce que un bare specifier n'a pas de remapping --> on pourrait ne pas log de warning dans ce cas -mais c'est dommage - -- ou parce que on trouve pas un fichier (parce qu'il serait remap ailleurs sans etre un bare specifier) --> use case rare mais pourquoi pas - -pour chaque bare specifier error -(donc pas dans importmap des node_modules) - -- sinon - -> suggerer que c'est une dépendance qu'il faut ajouter au package.json - non plutot un log de type debug - -si c'est pas un bare specifier et que le fichier est pas trouvé - --> warning et puis c'est tout - */ import { createLogger, createDetailedMessage } from "@jsenv/logger" @@ -39,13 +19,12 @@ export const getImportMapFromJsFiles = async ({ logLevel, importMap, projectDirectoryUrl, + removeUnusedMappings, magicExtensions = [".js", ".jsx", ".ts", ".tsx", ".node", ".json"], }) => { const logger = createLogger({ logLevel }) const projectPackageFileUrl = resolveUrl("./package.json", projectDirectoryUrl) - importMap = normalizeImportMap(importMap, projectDirectoryUrl) - const imports = {} const scopes = {} const addMapping = ({ scope, from, to }) => { @@ -59,18 +38,43 @@ export const getImportMapFromJsFiles = async ({ } } + const topLevelMappingsUsed = [] + const scopedMappingsUsed = {} + const markMappingAsUsed = ({ scope, from, to }) => { + if (scope) { + if (scope in scopedMappingsUsed) { + scopedMappingsUsed[scope].push({ from, to }) + } else { + scopedMappingsUsed[scope] = [{ from, to }] + } + } else { + topLevelMappingsUsed.push({ from, to }) + } + } + const importMapNormalized = normalizeImportMap(importMap, projectDirectoryUrl) + const trackAndResolveImport = (specifier, importer) => { + return resolveImport({ + specifier, + importer, + importMap: importMapNormalized, + defaultExtension: false, + onImportMapping: ({ scope, from }) => { + markMappingAsUsed({ + scope, + from, + to: scope ? importMap.scopes[scope][from] : importMap.imports[from], + }) + }, + createBareSpecifierError: () => BARE_SPECIFIER_ERROR, + }) + } + const visitFile = async (specifier, importer, { importedBy }) => { let fileUrl let gotBareSpecifierError = false try { - fileUrl = resolveImport({ - specifier, - importer, - importMap, - defaultExtension: false, - createBareSpecifierError: () => BARE_SPECIFIER_ERROR, - }) + fileUrl = trackAndResolveImport(specifier, importer) } catch (e) { if (e !== BARE_SPECIFIER_ERROR) { throw e @@ -107,6 +111,7 @@ export const getImportMapFromJsFiles = async ({ to: `./${urlToRelativeUrl(fileUrlOnFileSystem, projectDirectoryUrl)}`, } addMapping(autoMapping) + markMappingAsUsed(autoMapping) logger.warn( formatAutoMappingSpecifierWarning({ specifier, @@ -148,6 +153,26 @@ export const getImportMapFromJsFiles = async ({ : `${projectPackageFileUrl}`, }) + if (removeUnusedMappings) { + const importsUsed = {} + topLevelMappingsUsed.forEach(({ from, to }) => { + importsUsed[from] = to + }) + const scopesUsed = {} + Object.keys(scopedMappingsUsed).forEach((scope) => { + const mappingsUsed = scopedMappingsUsed[scope] + const scopedMappings = {} + mappingsUsed.forEach(({ from, to }) => { + scopedMappings[from] = to + }) + scopesUsed[scope] = scopedMappings + }) + return { + imports: importsUsed, + scopes: scopesUsed, + } + } + return { imports, scopes } } From dbc6c5af8c4d102b2e585201dd399def6fad2248 Mon Sep 17 00:00:00 2001 From: Damien Maillard Date: Fri, 12 Mar 2021 09:20:21 +0100 Subject: [PATCH 23/36] introduce optmizie importmap and warning --- .../from-js/getImportMapFromJsFiles.js | 61 +++++++++++-------- .../getImportMapFromPackageFiles.js | 19 +----- src/internal/optimizeImportMap.js | 19 ++++++ 3 files changed, 57 insertions(+), 42 deletions(-) create mode 100644 src/internal/optimizeImportMap.js diff --git a/src/internal/from-js/getImportMapFromJsFiles.js b/src/internal/from-js/getImportMapFromJsFiles.js index 7b0e1328..7d39b29b 100644 --- a/src/internal/from-js/getImportMapFromJsFiles.js +++ b/src/internal/from-js/getImportMapFromJsFiles.js @@ -1,7 +1,3 @@ -/* - -*/ - import { createLogger, createDetailedMessage } from "@jsenv/logger" import { resolveUrl, readFile, urlToExtension, urlToRelativeUrl } from "@jsenv/util" import { normalizeImportMap, resolveImport } from "@jsenv/import-map" @@ -20,11 +16,20 @@ export const getImportMapFromJsFiles = async ({ importMap, projectDirectoryUrl, removeUnusedMappings, + onWarn = (warning, warn) => { + warn(warning) + }, magicExtensions = [".js", ".jsx", ".ts", ".tsx", ".node", ".json"], }) => { const logger = createLogger({ logLevel }) const projectPackageFileUrl = resolveUrl("./package.json", projectDirectoryUrl) + const warn = (warning) => { + onWarn(warning, () => { + logger.warn(`\n${warning.message}\n`) + }) + } + const imports = {} const scopes = {} const addMapping = ({ scope, from, to }) => { @@ -87,8 +92,8 @@ export const getImportMapFromJsFiles = async ({ }) if (!fileUrlOnFileSystem) { - logger.warn( - formatFileNotFoundLog({ + warn( + createFileNotFoundWarning({ specifier, importedBy, fileUrl, @@ -112,7 +117,7 @@ export const getImportMapFromJsFiles = async ({ } addMapping(autoMapping) markMappingAsUsed(autoMapping) - logger.warn( + warn( formatAutoMappingSpecifierWarning({ specifier, importedBy, @@ -208,12 +213,17 @@ const magicExtensionWithImporterExtension = (magicExtensions, importer) => { return [importerExtension, ...magicExtensionsWithoutImporterExtension] } -const formatFileNotFoundLog = ({ specifier, importedBy, fileUrl, magicExtensions }) => { - return createDetailedMessage(`Cannot find file for "${specifier}"`, { - "imported by": importedBy, - "file url": fileUrl, - ...(urlToExtension(fileUrl) === "" ? { ["extensions tried"]: magicExtensions.join(`, `) } : {}), - }) +const createFileNotFoundWarning = ({ specifier, importedBy, fileUrl, magicExtensions }) => { + return { + code: "FILE_NOT_FOUND", + message: createDetailedMessage(`Cannot find file for "${specifier}"`, { + "specifier origin": importedBy, + "file url tried": fileUrl, + ...(urlToExtension(fileUrl) === "" + ? { ["extensions tried"]: magicExtensions.join(`, `) } + : {}), + }), + } } const formatAutoMappingSpecifierWarning = ({ @@ -222,16 +232,17 @@ const formatAutoMappingSpecifierWarning = ({ closestPackageDirectoryUrl, closestPackageObject, }) => { - return ` -${createDetailedMessage(`Auto mapping ${autoMapping.from} to ${autoMapping.to}.`, { - "specifier origin": importedBy, - "suggestion": decideAutoMappingSuggestion({ - autoMapping, - closestPackageDirectoryUrl, - closestPackageObject, - }), -})} -` + return { + code: "AUTO_MAPPING", + message: createDetailedMessage(`Auto mapping ${autoMapping.from} to ${autoMapping.to}.`, { + "specifier origin": importedBy, + "suggestion": decideAutoMappingSuggestion({ + autoMapping, + closestPackageDirectoryUrl, + closestPackageObject, + }), + }), + } } const decideAutoMappingSuggestion = ({ @@ -245,12 +256,12 @@ const decideAutoMappingSuggestion = ({ closestPackageDirectoryUrl, ) - return `Add + return `To get rid of this warning, add an explicit mapping into importmap file. ${mappingToImportmapString(autoMapping)} into ${packageImportmapFileUrl}.` } - return `Add + return `To get rid of this warning, add an explicit mapping into package.json. ${mappingToExportsFieldString(autoMapping)} into ${closestPackageDirectoryUrl}package.json.` } diff --git a/src/internal/from-package/getImportMapFromPackageFiles.js b/src/internal/from-package/getImportMapFromPackageFiles.js index 954bf017..02344e7f 100644 --- a/src/internal/from-package/getImportMapFromPackageFiles.js +++ b/src/internal/from-package/getImportMapFromPackageFiles.js @@ -7,6 +7,7 @@ import { urlToBasename, readFile, } from "@jsenv/util" +import { optimizeImportMap } from "../optimizeImportMap.js" import { resolvePackageMain } from "./resolvePackageMain.js" import { visitPackageImportMap } from "./visitPackageImportMap.js" import { visitPackageExports } from "./visitPackageExports.js" @@ -469,23 +470,7 @@ export const getImportMapFromPackageFiles = async ({ includeDevDependencies: projectPackageDevDependenciesIncluded, }) - // remove useless duplicates (scoped key+value already defined on imports) - Object.keys(scopes).forEach((key) => { - const scopedImports = scopes[key] - Object.keys(scopedImports).forEach((scopedImportKey) => { - if ( - scopedImportKey in imports && - imports[scopedImportKey] === scopedImports[scopedImportKey] - ) { - delete scopedImports[scopedImportKey] - } - }) - if (Object.keys(scopedImports).length === 0) { - delete scopes[key] - } - }) - - return { imports, scopes } + return optimizeImportMap({ imports, scopes }) } const packageDependenciesFromPackageObject = (packageObject, { includeDevDependencies }) => { diff --git a/src/internal/optimizeImportMap.js b/src/internal/optimizeImportMap.js new file mode 100644 index 00000000..20edecd2 --- /dev/null +++ b/src/internal/optimizeImportMap.js @@ -0,0 +1,19 @@ +export const optimizeImportMap = ({ imports, scopes }) => { + // remove useless duplicates (scoped key+value already defined on imports) + const scopesOptimized = {} + Object.keys(scopes).forEach((scope) => { + const scopeMappings = scopes[scope] + const scopeMappingsOptimized = {} + Object.keys(scopeMappings).forEach((mappingKey) => { + const topLevelMappingValue = imports[mappingKey] + const mappingValue = scopeMappings[mappingKey] + if (!topLevelMappingValue || topLevelMappingValue !== mappingValue) { + scopeMappingsOptimized[mappingKey] = mappingValue + } + }) + if (Object.keys(scopeMappingsOptimized).length > 0) { + scopesOptimized[scope] = scopeMappingsOptimized + } + }) + return { imports, scopes: scopesOptimized } +} From 1447db307bb88b7719b0f59896338f85a5124405 Mon Sep 17 00:00:00 2001 From: Damien Maillard Date: Fri, 12 Mar 2021 09:28:29 +0100 Subject: [PATCH 24/36] Test warning for extensionless import --- src/getImportMapFromProjectFiles.js | 2 + src/internal/from-js/showSource.js | 4 +- .../extensionless-js/extensionless-js.test.js | 40 ++++++++++++++++--- 3 files changed, 38 insertions(+), 8 deletions(-) diff --git a/src/getImportMapFromProjectFiles.js b/src/getImportMapFromProjectFiles.js index 4dfdca4b..86a94f1d 100644 --- a/src/getImportMapFromProjectFiles.js +++ b/src/getImportMapFromProjectFiles.js @@ -11,6 +11,7 @@ export const getImportMapFromProjectFiles = async ({ jsFiles = false, removeUnusedMappings = !dev, magicExtensions, + onWarn, ...rest }) => { const packagesExportsPreference = [ @@ -32,6 +33,7 @@ export const getImportMapFromProjectFiles = async ({ let importMapFromJsFiles = jsFiles ? await getImportMapFromJsFiles({ logLevel, + onWarn, importMap: importMapFromPackageFiles, removeUnusedMappings, projectDirectoryUrl, diff --git a/src/internal/from-js/showSource.js b/src/internal/from-js/showSource.js index 7df0a607..ba5aa249 100644 --- a/src/internal/from-js/showSource.js +++ b/src/internal/from-js/showSource.js @@ -20,12 +20,10 @@ export const showSource = ({ url, line, column, source }) => { } return `${message} - ${showSourceLocation(source, { line, column, -})} -` +})}` } const red = "\x1b[31m" diff --git a/test/getImportMapFromProjectFiles/from-js/extensionless-js/extensionless-js.test.js b/test/getImportMapFromProjectFiles/from-js/extensionless-js/extensionless-js.test.js index 1b016334..98f73729 100644 --- a/test/getImportMapFromProjectFiles/from-js/extensionless-js/extensionless-js.test.js +++ b/test/getImportMapFromProjectFiles/from-js/extensionless-js/extensionless-js.test.js @@ -4,15 +4,45 @@ import { getImportMapFromProjectFiles } from "@jsenv/node-module-import-map" const testDirectoryUrl = resolveUrl("./root/", import.meta.url) -const actual = await getImportMapFromProjectFiles({ +const warnings = [] +const importmap = await getImportMapFromProjectFiles({ projectDirectoryUrl: testDirectoryUrl, jsFiles: true, + onWarn: (warning) => { + warnings.push(warning) + }, }) +const actual = { + warnings, + importmap, +} const expected = { - imports: { - "./file": "./file.js", - "root": "./index.js", + warnings: [ + { + code: "AUTO_MAPPING", + message: `Auto mapping ./file to ./file.js. +--- specifier origin --- +${testDirectoryUrl}index.js:2:7 + 1 | // eslint-disable-next-line import/no-unresolved +> 2 | import "./file" + | ^ + 3 |${" "} +--- suggestion --- +To get rid of this warning, add an explicit mapping into package.json. +{ + "exports": { + "./file": "./file.js" + } +} +into ${testDirectoryUrl}package.json.`, + }, + ], + importmap: { + imports: { + "./file": "./file.js", + "root": "./index.js", + }, + scopes: {}, }, - scopes: {}, } assert({ actual, expected }) From 749b62cdbba28bd6eb778f7e274a9471eae0591c Mon Sep 17 00:00:00 2001 From: Damien Maillard Date: Fri, 12 Mar 2021 09:50:48 +0100 Subject: [PATCH 25/36] extend warning concept --- src/getImportMapFromProjectFiles.js | 17 +++- .../from-js/getImportMapFromJsFiles.js | 14 +-- .../getImportMapFromPackageFiles.js | 91 ++++++++++--------- .../from-package/resolvePackageMain.js | 70 +++++++++----- .../from-package/visitPackageExports.js | 67 ++++++++------ .../from-package/visitPackageImportMap.js | 15 +-- 6 files changed, 160 insertions(+), 114 deletions(-) diff --git a/src/getImportMapFromProjectFiles.js b/src/getImportMapFromProjectFiles.js index 86a94f1d..f4471f23 100644 --- a/src/getImportMapFromProjectFiles.js +++ b/src/getImportMapFromProjectFiles.js @@ -1,4 +1,5 @@ import { sortImportMap, composeTwoImportMaps } from "@jsenv/import-map" +import { createLogger } from "@jsenv/logger" import { getImportMapFromJsFiles } from "./internal/from-js/getImportMapFromJsFiles.js" import { getImportMapFromPackageFiles } from "./internal/from-package/getImportMapFromPackageFiles.js" @@ -11,7 +12,9 @@ export const getImportMapFromProjectFiles = async ({ jsFiles = false, removeUnusedMappings = !dev, magicExtensions, - onWarn, + onWarn = (warning, warn) => { + warn(warning) + }, ...rest }) => { const packagesExportsPreference = [ @@ -20,9 +23,17 @@ export const getImportMapFromProjectFiles = async ({ ...(dev ? "development" : "production"), ] + const logger = createLogger({ logLevel }) + const warn = (warning) => { + onWarn(warning, () => { + logger.warn(`\n${warning.message}\n`) + }) + } + // At this point, importmap is relative to the project directory url let importMapFromPackageFiles = await getImportMapFromPackageFiles({ - logLevel, + logger, + warn, projectDirectoryUrl, packagesExportsPreference, projectPackageDevDependenciesIncluded: dev, @@ -33,7 +44,7 @@ export const getImportMapFromProjectFiles = async ({ let importMapFromJsFiles = jsFiles ? await getImportMapFromJsFiles({ logLevel, - onWarn, + warn, importMap: importMapFromPackageFiles, removeUnusedMappings, projectDirectoryUrl, diff --git a/src/internal/from-js/getImportMapFromJsFiles.js b/src/internal/from-js/getImportMapFromJsFiles.js index 7d39b29b..29c21a73 100644 --- a/src/internal/from-js/getImportMapFromJsFiles.js +++ b/src/internal/from-js/getImportMapFromJsFiles.js @@ -1,4 +1,4 @@ -import { createLogger, createDetailedMessage } from "@jsenv/logger" +import { createDetailedMessage } from "@jsenv/logger" import { resolveUrl, readFile, urlToExtension, urlToRelativeUrl } from "@jsenv/util" import { normalizeImportMap, resolveImport } from "@jsenv/import-map" import { @@ -12,24 +12,14 @@ import { resolveFile } from "../resolveFile.js" const BARE_SPECIFIER_ERROR = {} export const getImportMapFromJsFiles = async ({ - logLevel, + warn, importMap, projectDirectoryUrl, removeUnusedMappings, - onWarn = (warning, warn) => { - warn(warning) - }, magicExtensions = [".js", ".jsx", ".ts", ".tsx", ".node", ".json"], }) => { - const logger = createLogger({ logLevel }) const projectPackageFileUrl = resolveUrl("./package.json", projectDirectoryUrl) - const warn = (warning) => { - onWarn(warning, () => { - logger.warn(`\n${warning.message}\n`) - }) - } - const imports = {} const scopes = {} const addMapping = ({ scope, from, to }) => { diff --git a/src/internal/from-package/getImportMapFromPackageFiles.js b/src/internal/from-package/getImportMapFromPackageFiles.js index 02344e7f..127f4dab 100644 --- a/src/internal/from-package/getImportMapFromPackageFiles.js +++ b/src/internal/from-package/getImportMapFromPackageFiles.js @@ -1,4 +1,4 @@ -import { createLogger, createDetailedMessage } from "@jsenv/logger" +import { createDetailedMessage } from "@jsenv/logger" import { resolveUrl, urlToRelativeUrl, @@ -18,7 +18,8 @@ export const getImportMapFromPackageFiles = async ({ // it's not very important but it would be better to register on it // an stops what we are doing if asked to do so // cancellationToken = createCancellationTokenForProcess(), - logLevel, + logger, + warn, projectDirectoryUrl, projectPackageDevDependenciesIncluded = process.env.NODE_ENV !== "production", packagesExportsPreference = ["import", "browser"], @@ -26,8 +27,6 @@ export const getImportMapFromPackageFiles = async ({ packagesManualOverrides = {}, packageIncludedPredicate = () => true, }) => { - const logger = createLogger({ logLevel }) - projectDirectoryUrl = assertAndNormalizeDirectoryUrl(projectDirectoryUrl) const projectPackageFileUrl = resolveUrl("./package.json", projectDirectoryUrl) @@ -242,7 +241,7 @@ export const getImportMapFromPackageFiles = async ({ } const importsFromPackageField = await visitPackageImportMap({ - logger, + warn, packageFileUrl, packageJsonObject, projectDirectoryUrl, @@ -252,6 +251,7 @@ export const getImportMapFromPackageFiles = async ({ if (packagesExportsIncluded && "exports" in packageJsonObject) { const mappingsFromPackageExports = {} visitPackageExports({ + warn, packageFileUrl, packageJsonObject, packageName, @@ -278,19 +278,14 @@ export const getImportMapFromPackageFiles = async ({ return } - logger.warn( - formatWilcardExportsIgnoredWarning({ + warn( + createExportsWildcardIgnoredWarning({ key, value, packageFileUrl, }), ) }, - onWarn: (warning) => { - logger.warn(` - ${warning} - `) - }, }) addMappingsForPackageAndImporter(mappingsFromPackageExports) } @@ -308,7 +303,7 @@ export const getImportMapFromPackageFiles = async ({ }, }) => { const mainFileUrl = await resolvePackageMain({ - logger, + warn, packagesExportsPreference, packageFileUrl, packageJsonObject, @@ -376,13 +371,16 @@ export const getImportMapFromPackageFiles = async ({ dependencyName, }) if (!dependencyData) { - logger[dependencyInfo.isOptional ? "debug" : "warn"]( - formatCannotFindPackageLog({ - dependencyName, - dependencyInfo, - packageFileUrl, - }), - ) + const cannotFindPackageWarning = createCannotFindPackageWarning({ + dependencyName, + dependencyInfo, + packageFileUrl, + }) + if (dependencyInfo.isOptional) { + logger.debug(cannotFindPackageWarning.message) + } else { + warn(cannotFindPackageWarning) + } return } @@ -455,8 +453,11 @@ export const getImportMapFromPackageFiles = async ({ const packageName = projectPackageJsonObject.name if (typeof packageName !== "string") { - logger.warn( - formatUnexpectedPackageNameLog({ packageName, packageFileUrl: projectPackageFileUrl }), + warn( + createPackageNameMustBeAStringWarning({ + packageName, + packageFileUrl: projectPackageFileUrl, + }), ) return {} } @@ -529,8 +530,10 @@ const moveMappingValue = (address, from, to) => { return `./${relativeUrl}` } -const formatWilcardExportsIgnoredWarning = ({ key, value, packageFileUrl }) => { - return `Ignoring export using "*" because it is not supported by importmap. +const createExportsWildcardIgnoredWarning = ({ key, value, packageFileUrl }) => { + return { + code: "EXPORTS_WILDCARD", + message: `Ignoring export using "*" because it is not supported by importmap. --- key --- ${key} --- value --- @@ -538,33 +541,35 @@ ${value} --- package.json path --- ${urlToFileSystemPath(packageFileUrl)} --- see also --- -https://github.com/WICG/import-maps/issues/232` +https://github.com/WICG/import-maps/issues/232`, + } } -const formatUnexpectedPackageNameLog = ({ packageName, packageFileUrl }) => { - return ` -package name field must be a string +const createPackageNameMustBeAStringWarning = ({ packageName, packageFileUrl }) => { + return { + code: "PACKAGE_NAME_MUST_BE_A_STRING", + message: `package name field must be a string --- package name field --- ${packageName} --- package.json file path --- -${packageFileUrl} -` +${packageFileUrl}`, + } } -const formatCannotFindPackageLog = ({ dependencyName, dependencyInfo, packageFileUrl }) => { +const createCannotFindPackageWarning = ({ dependencyName, dependencyInfo, packageFileUrl }) => { const dependencyIsOptional = dependencyInfo.isOptional const dependencyType = dependencyInfo.type const dependencyVersionPattern = dependencyInfo.versionPattern - const detailedMessage = createDetailedMessage( - dependencyIsOptional - ? `cannot find an optional ${dependencyType}.` - : `cannot find a ${dependencyType}.`, - { - [dependencyType]: `${dependencyName}@${dependencyVersionPattern}`, - "required by": urlToFileSystemPath(packageFileUrl), - }, - ) - return ` -${detailedMessage} -` + return { + code: "CANNOT_FIND_PACKAGE", + message: createDetailedMessage( + dependencyIsOptional + ? `cannot find an optional ${dependencyType}.` + : `cannot find a ${dependencyType}.`, + { + [dependencyType]: `${dependencyName}@${dependencyVersionPattern}`, + "required by": urlToFileSystemPath(packageFileUrl), + }, + ), + } } diff --git a/src/internal/from-package/resolvePackageMain.js b/src/internal/from-package/resolvePackageMain.js index f2590a3e..5a3c9c4d 100644 --- a/src/internal/from-package/resolvePackageMain.js +++ b/src/internal/from-package/resolvePackageMain.js @@ -5,14 +5,14 @@ import { resolveFile } from "../resolveFile.js" const magicExtensions = [".js", ".json", ".node"] export const resolvePackageMain = ({ - logger, + warn, packagesExportsPreference, packageFileUrl, packageJsonObject, }) => { if (packagesExportsPreference.includes("import") && "module" in packageJsonObject) { return resolveMainFile({ - logger, + warn, packageFileUrl, packageMainFieldName: "module", packageMainFieldValue: packageJsonObject.module, @@ -21,7 +21,7 @@ export const resolvePackageMain = ({ if (packagesExportsPreference.includes("import") && "jsnext:main" in packageJsonObject) { return resolveMainFile({ - logger, + warn, packageFileUrl, packageMainFieldName: "jsnext:main", packageMainFieldValue: packageJsonObject["jsnext:main"], @@ -30,7 +30,7 @@ export const resolvePackageMain = ({ if (packagesExportsPreference.includes("browser") && "browser" in packageJsonObject) { return resolveMainFile({ - logger, + warn, packageFileUrl, packageMainFieldName: "browser", packageMainFieldValue: packageJsonObject.browser, @@ -39,7 +39,7 @@ export const resolvePackageMain = ({ if ("main" in packageJsonObject) { return resolveMainFile({ - logger, + warn, packageFileUrl, packageMainFieldName: "main", packageMainFieldValue: packageJsonObject.main, @@ -47,7 +47,7 @@ export const resolvePackageMain = ({ } return resolveMainFile({ - logger, + warn, packageFileUrl, packageMainFieldName: "default", packageMainFieldValue: "index", @@ -55,7 +55,7 @@ export const resolvePackageMain = ({ } const resolveMainFile = async ({ - logger, + warn, packageFileUrl, packageMainFieldName, packageMainFieldValue, @@ -66,7 +66,6 @@ const resolveMainFile = async ({ return null } - const packageFilePath = urlToFileSystemPath(packageFileUrl) const packageDirectoryUrl = resolveUrl("./", packageFileUrl) const mainFileRelativeUrl = packageMainFieldValue.endsWith("/") ? `${packageMainFieldValue}index` @@ -75,14 +74,12 @@ const resolveMainFile = async ({ const mainFileUrlFirstCandidate = resolveUrl(mainFileRelativeUrl, packageFileUrl) if (!mainFileUrlFirstCandidate.startsWith(packageDirectoryUrl)) { - logger.warn( - ` -${packageMainFieldName} field in package.json must be inside package.json folder. ---- ${packageMainFieldName} --- -${packageMainFieldValue} ---- package.json path --- -${packageFilePath} -`, + warn( + createPackageMainFileMustBeRelativeWarning({ + packageMainFieldName, + packageMainFieldValue, + packageFileUrl, + }), ) return null } @@ -99,8 +96,8 @@ ${packageFilePath} // otherwise the package.json is missing the main field // it certainly means it's not important if (packageMainFieldName !== "default") { - logger.warn( - formatFileNotFoundLog({ + warn( + createPackageMainFileNotFoundWarning({ specifier: packageMainFieldValue, importedIn: `${packageFileUrl}#${packageMainFieldName}`, fileUrl: mainFileUrlFirstCandidate, @@ -114,10 +111,35 @@ ${packageFilePath} return mainFileUrl } -const formatFileNotFoundLog = ({ specifier, importedIn, fileUrl, magicExtensions }) => { - return createDetailedMessage(`Cannot find file for "${specifier}"`, { - "imported in": importedIn, - "file url": fileUrl, - ...(urlToExtension(fileUrl) === "" ? { ["extensions tried"]: magicExtensions.join(`, `) } : {}), - }) +const createPackageMainFileMustBeRelativeWarning = ({ + packageMainFieldName, + packageMainFieldValue, + packageFileUrl, +}) => { + return { + code: "PACKAGE_MAIN_FILE_MUST_BE_RELATIVE", + message: `${packageMainFieldName} field in package.json must be inside package.json folder. +--- ${packageMainFieldName} --- +${packageMainFieldValue} +--- package.json path --- +${urlToFileSystemPath(packageFileUrl)}`, + } +} + +const createPackageMainFileNotFoundWarning = ({ + specifier, + importedIn, + fileUrl, + magicExtensions, +}) => { + return { + code: "PACKAGE_MAIN_FILE_NOT_FOUND", + message: createDetailedMessage(`Cannot find file for "${specifier}"`, { + "imported in": importedIn, + "file url tried": fileUrl, + ...(urlToExtension(fileUrl) === "" + ? { ["extensions tried"]: magicExtensions.join(`, `) } + : {}), + }), + } } diff --git a/src/internal/from-package/visitPackageExports.js b/src/internal/from-package/visitPackageExports.js index 463c3af5..7ef8bda1 100644 --- a/src/internal/from-package/visitPackageExports.js +++ b/src/internal/from-package/visitPackageExports.js @@ -4,6 +4,7 @@ import { urlToFileSystemPath, urlToRelativeUrl, resolveUrl } from "@jsenv/util" import { specifierIsRelative } from "./specifierIsRelative.js" export const visitPackageExports = ({ + warn, packageFileUrl, packageJsonObject, packageExports = packageJsonObject.exports, @@ -11,15 +12,14 @@ export const visitPackageExports = ({ projectDirectoryUrl, packagesExportsPreference, onExport, - onWarn, }) => { const packageDirectoryUrl = resolveUrl("./", packageFileUrl) const packageDirectoryRelativeUrl = urlToRelativeUrl(packageDirectoryUrl, projectDirectoryUrl) visitExportsSubpath(packageExports, packagesExportsPreference, { onUnexpectedPackageExports: ({ packageExportsValue, packageExportsValuePath }) => { - onWarn( - formatExportsIsUnexpectedWarning({ + warn( + createExportsValueWarning({ packageExportsValue, packageExportsValuePath, packageFileUrl, @@ -28,8 +28,8 @@ export const visitPackageExports = ({ }, onMixedPackageExports: ({ packageExportsValue, packageExportsValuePath }) => { // see https://nodejs.org/dist/latest-v13.x/docs/api/esm.html#esm_exports_sugar - onWarn( - formatExportsUnexpectedMixWarning({ + warn( + createExportsMixedWarning({ packageExportsValue, packageExportsValuePath, packageFileUrl, @@ -38,8 +38,8 @@ export const visitPackageExports = ({ }, onSubpathPackageExport: ({ key, value, valuePath }) => { if (!specifierIsRelative(key)) { - onWarn( - formatExportsKeyMustBeRelativeWarning({ + warn( + createExportsMappingKeyMustBeRelativeWarning({ key, keyPath: valuePath.slice(0, -1), packageFileUrl, @@ -48,8 +48,8 @@ export const visitPackageExports = ({ return } if (typeof value !== "string") { - onWarn( - formatExportsValueMustBeStringWarning({ + warn( + createExportsMappingValueMustBeAStringWarning({ value, valuePath, packageFileUrl, @@ -58,8 +58,8 @@ export const visitPackageExports = ({ return } if (!specifierIsRelative(value)) { - onWarn( - formatExportsValueMustBeRelativeWarning({ + warn( + createExportsMappingValueMustBeRelativeWarning({ value, valuePath, packageFileUrl, @@ -184,60 +184,75 @@ const addressToDestination = (address, packageDirectoryRelativeUrl) => { return `./${packageDirectoryRelativeUrl}${address}` } -const formatExportsIsUnexpectedWarning = ({ +const createExportsValueWarning = ({ packageExportsValue, packageExportsValuePath, packageFileUrl, }) => { - return `unexpected value in package.json exports field: value must be an object or a string. + return { + code: "EXPORTS_VALUE", + message: `unexpected value in package.json exports field: value must be an object or a string. --- value --- ${packageExportsValue} --- value path --- ${packageExportsValuePath.join(".")} --- package.json path --- -${urlToFileSystemPath(packageFileUrl)}` +${urlToFileSystemPath(packageFileUrl)}`, + } } -const formatExportsUnexpectedMixWarning = ({ +const createExportsMixedWarning = ({ packageExportsValue, packageExportsValuePath, packageFileUrl, }) => { - return `unexpected package.json exports field: cannot mix conditional and subpath exports. + return { + code: "EXPORTS_MIXED", + message: `unexpected package.json exports field: cannot mix conditional and subpath exports. --- value --- ${JSON.stringify(packageExportsValue, null, " ")} --- value path --- ${packageExportsValuePath.join(".")} --- package.json path --- -${urlToFileSystemPath(packageFileUrl)}` +${urlToFileSystemPath(packageFileUrl)}`, + } } -const formatExportsKeyMustBeRelativeWarning = ({ key, keyPath, packageFileUrl }) => { - return `unexpected key in package.json exports field: key must be relative. +const createExportsMappingKeyMustBeRelativeWarning = ({ key, keyPath, packageFileUrl }) => { + return { + code: "EXPORTS_MAPPING_KEY_MUST_BE_RELATIVE", + message: `unexpected key in package.json exports field: key must be relative. --- key --- ${key} --- key path --- ${keyPath.join(".")} --- package.json path --- -${urlToFileSystemPath(packageFileUrl)}` +${urlToFileSystemPath(packageFileUrl)}`, + } } -const formatExportsValueMustBeStringWarning = ({ value, valuePath, packageFileUrl }) => { - return `unexpected value in package.json exports field: value must be a string. +const createExportsMappingValueMustBeAStringWarning = ({ value, valuePath, packageFileUrl }) => { + return { + code: "EXPORTS_MAPPING_VALUE_MUST_BE_A_STRING", + message: `unexpected value in package.json exports field: value must be a string. --- value --- ${value} --- value path --- ${valuePath.join(".")} --- package.json path --- -${urlToFileSystemPath(packageFileUrl)}` +${urlToFileSystemPath(packageFileUrl)}`, + } } -const formatExportsValueMustBeRelativeWarning = ({ value, valuePath, packageFileUrl }) => { - return `unexpected value in package.json exports field: value must be relative. +const createExportsMappingValueMustBeRelativeWarning = ({ value, valuePath, packageFileUrl }) => { + return { + code: "EXPORTS_MAPPING_VALUE_MUST_BE_RELATIVE", + message: `unexpected value in package.json exports field: value must be relative. --- value --- ${value} --- value path --- ${valuePath.join(".")} --- package.json path --- -${urlToFileSystemPath(packageFileUrl)}` +${urlToFileSystemPath(packageFileUrl)}`, + } } diff --git a/src/internal/from-package/visitPackageImportMap.js b/src/internal/from-package/visitPackageImportMap.js index 20c76313..97fe1345 100644 --- a/src/internal/from-package/visitPackageImportMap.js +++ b/src/internal/from-package/visitPackageImportMap.js @@ -2,7 +2,7 @@ import { resolveUrl, moveImportMap } from "@jsenv/import-map" import { readFile, urlToFileSystemPath } from "@jsenv/util" export const visitPackageImportMap = async ({ - logger, + warn, packageFileUrl, packageJsonObject, packageImportmap = packageJsonObject.importmap, @@ -22,8 +22,8 @@ export const visitPackageImportMap = async ({ return packageImportmap } - logger.warn( - formatUnexpectedPackageImportmapWarning({ + warn( + createPackageImportMapUnexpectedWarning({ packageImportmap, packageFileUrl, }), @@ -31,10 +31,13 @@ export const visitPackageImportMap = async ({ return {} } -const formatUnexpectedPackageImportmapWarning = ({ packageImportmap, packageFileUrl }) => { - return `unexpected value in package.json importmap field: value must be a string or an object. +const createPackageImportMapUnexpectedWarning = ({ packageImportmap, packageFileUrl }) => { + return { + code: "PACKAGE_IMPORTMAP_UNEXPECTED", + message: `unexpected value in package.json importmap field: value must be a string or an object. --- value --- ${packageImportmap} --- package.json path --- -${urlToFileSystemPath(packageFileUrl)}` +${urlToFileSystemPath(packageFileUrl)}`, + } } From c689c151d4c9ff907f3ca5f060254c147a6641e4 Mon Sep 17 00:00:00 2001 From: Damien Maillard Date: Fri, 12 Mar 2021 10:01:12 +0100 Subject: [PATCH 26/36] update doc --- index.js | 2 +- readme.md | 213 +++++++++--------- .../generate-import-map.js | 7 +- ...MapForProject.js => writeImportMapFile.js} | 2 +- 4 files changed, 108 insertions(+), 116 deletions(-) rename src/{generateImportMapForProject.js => writeImportMapFile.js} (97%) diff --git a/index.js b/index.js index 5368c3cb..6d42ed7d 100644 --- a/index.js +++ b/index.js @@ -1,3 +1,3 @@ export { getImportMapFromProjectFiles } from "./src/getImportMapFromProjectFiles.js" export { getImportMapFromFile } from "./src/getImportMapFromFile.js" -export { generateImportMapForProject } from "./src/generateImportMapForProject.js" +export { writeImportMapFile } from "./src/writeImportMapFile.js" diff --git a/readme.md b/readme.md index e5272e60..baa926eb 100644 --- a/readme.md +++ b/readme.md @@ -11,12 +11,12 @@ Generate importmap for node_modules. - [Presentation](#Presentation) - [Usage](#Usage) -- [Extensionless import warning](#Extensionless-import-warning) -- [Subpath import warning](#Subpath-import-warning) -- [generateImportMapForProject](#generateImportMapForProject) +- [writeImportMapFile](#writeImportMapFile) - [getImportMapFromProjectFiles](#getImportMapFromProjectFiles) - [getImportMapFromFile](#getImportMapFromFile) - [Custom node module resolution](#custom-node-module-resolution) +- [Extensionless import warning](#Extensionless-import-warning) +- [Subpath import warning](#Subpath-import-warning) - [Concrete example](#concrete-example) # Presentation @@ -51,14 +51,11 @@ npm install --save-dev @jsenv/node-module-import-map 2 - Create generate-import-map.js ```js -import { - getImportMapFromNodeModules, - generateImportMapForProject, -} from "@jsenv/node-module-import-map" +import { getImportMapFromNodeModules, writeImportMapFile } from "@jsenv/node-module-import-map" const projectDirectoryUrl = new URL("./", import.meta.url) -await generateImportMapForProject( +await writeImportMapFile( [ getImportMapFromProjectFiles({ projectDirectoryUrl, @@ -75,14 +72,11 @@ await generateImportMapForProject( See commonjs equivalent of code above ```js -const { - getImportMapFromNodeModules, - generateImportMapForProject, -} = require("@jsenv/node-module-import-map") +const { getImportMapFromNodeModules, writeImportMapFile } = require("@jsenv/node-module-import-map") const projectDirectoryUrl = __dirname -await generateImportMapForProject( +await writeImportMapFile( [ getImportMapFromProjectFiles({ projectDirectoryUrl, @@ -137,103 +131,14 @@ If you use a bundler, be sure it's compatible with import maps.
-# Extensionless import warning - -If the code you wants to run contains one ore more extensionless path specifier, it will not be found by a browser (not even by Node.js). - -
- extensionless import example - -```js -import { foo } from "./file" -``` - -
- -In this situation, you can do one of the following: - -1. Add extension in the source file -2. If there is a build step, ensure extension are added during the build -3. Add remapping in `exports` field of your `package.json` - -```json -{ - "exports": { - "./file": "./file.js" - } -} -``` - -4. Remap manually each extensionless import and pass that importmap in [importMapInputs](#importMapInputs) - -# Subpath import warning - -The generation of importmap takes into account `exports` field from `package.json`. These `exports` field are used to allow subpath imports. - -
- subpath import example - -```js -import { foo } from "my-module/feature/index.js" -import { bar } from "my-module/feature-b" -``` - -For the above import to work, `my-module/package.json` must contain the following `exports` field. - -```json -{ - "name": "my-module", - "exports": { - "./*": "./*", - "./feature-b": "./feature-b/index.js" - } -} -``` - -Read more in [Node.js documentation about package entry points](https://nodejs.org/dist/latest-v15.x/docs/api/packages.html#packages_package_entry_points) - -
- -Node.js allows to put `*` in `exports` field. There is an importmap equivalent when `*` is used for directory/folder remapping. - -```json -{ - "exports": { - "./feature/*": "./feature/*" - } -} -``` - -Becomes the following importmap - -```json -{ - "imports": { - "./feature/": "./feature/" - } -} -``` - -However using `*` to add file extension as in - -```json -{ - "exports": { - "./feature/*": "./feature/*.js" - } -} -``` - -**is not supported in importmap**. Nothing suggests it will be supported for now, read more in https://github.com/WICG/import-maps/issues/232. - -# generateImportMapForProject +# writeImportMapFile -`generateImportMapForProject` is an async function receiving an array of promise resolving to importmaps. It awaits for every importmap, compose them into one and write it into a file. +`writeImportMapFile` is an async function receiving an array of promise resolving to importmaps. It awaits for every importmap, compose them into one and write it into a file. > This function is meant to be responsible of generating the final importMap file that a project uses.
- generateImportMapForProject code example + writeImportMapFile code example Code below generate an import map from node_modules + a file + an inline importmap. @@ -241,7 +146,7 @@ Code below generate an import map from node_modules + a file + an inline importm import { getImportMapFromProjectFiles, getImportMapFromFile, - generateImportMapForProject, + writeImportMapFile, } from "@jsenv/node-module-import-map" const projectDirectoryUrl = new URL("./", import.meta.url) @@ -261,13 +166,13 @@ const importMapInputs = [ }, ] -await generateImportMapForProject(importMapInputs, { +await writeImportMapFile(importMapInputs, { projectDirectoryUrl, importMapFileRelativeUrl: "./import-map.importmap", }) ``` -— source code at [src/generateImportMapForProject.js](./src/generateImportMapForProject.js) +— source code at [src/writeImportMapFile.js](./src/writeImportMapFile.js)
@@ -303,7 +208,8 @@ import { getImportMapFromProjectFiles } from "@jsenv/node-module-import-map" const importMap = await getImportMapFromProjectFiles({ projectDirectoryUrl: new URL("./", import.meta.url), - dev: true, + dev: false, + runtime: "browser", }) ``` @@ -370,6 +276,95 @@ We do this because import map are used on the web where a file outside project d In practice, it has no impact because node modules are inside your project directory. If they are not, ensure all your dependencies are in your `package.json` and re-run `npm install`. +# Extensionless import warning + +If the code you wants to run contains one ore more extensionless path specifier, it will not be found by a browser (not even by Node.js). + +
+ extensionless import example + +```js +import { foo } from "./file" +``` + +
+ +In this situation, you can do one of the following: + +1. Add extension in the source file +2. If there is a build step, ensure extension are added during the build +3. Add remapping in `exports` field of your `package.json` + +```json +{ + "exports": { + "./file": "./file.js" + } +} +``` + +4. Remap manually each extensionless import and pass that importmap in [importMapInputs](#importMapInputs) + +# Subpath import warning + +The generation of importmap takes into account `exports` field from `package.json`. These `exports` field are used to allow subpath imports. + +
+ subpath import example + +```js +import { foo } from "my-module/feature/index.js" +import { bar } from "my-module/feature-b" +``` + +For the above import to work, `my-module/package.json` must contain the following `exports` field. + +```json +{ + "name": "my-module", + "exports": { + "./*": "./*", + "./feature-b": "./feature-b/index.js" + } +} +``` + +Read more in [Node.js documentation about package entry points](https://nodejs.org/dist/latest-v15.x/docs/api/packages.html#packages_package_entry_points) + +
+ +Node.js allows to put `*` in `exports` field. There is an importmap equivalent when `*` is used for directory/folder remapping. + +```json +{ + "exports": { + "./feature/*": "./feature/*" + } +} +``` + +Becomes the following importmap + +```json +{ + "imports": { + "./feature/": "./feature/" + } +} +``` + +However using `*` to add file extension as in + +```json +{ + "exports": { + "./feature/*": "./feature/*.js" + } +} +``` + +**is not supported in importmap**. Nothing suggests it will be supported for now, read more in https://github.com/WICG/import-maps/issues/232. + # Concrete example This part explains how to setup a real environment to see `@jsenv/node-module-import-map` in action. diff --git a/script/generate-import-map/generate-import-map.js b/script/generate-import-map/generate-import-map.js index 5f63f4ee..fa0ce6a7 100644 --- a/script/generate-import-map/generate-import-map.js +++ b/script/generate-import-map/generate-import-map.js @@ -1,10 +1,7 @@ -import { - getImportMapFromProjectFiles, - generateImportMapForProject, -} from "@jsenv/node-module-import-map" +import { getImportMapFromProjectFiles, writeImportMapFile } from "@jsenv/node-module-import-map" import { projectDirectoryUrl, importMapFileRelativeUrl } from "../../jsenv.config.js" -generateImportMapForProject( +writeImportMapFile( [ getImportMapFromProjectFiles({ projectDirectoryUrl, diff --git a/src/generateImportMapForProject.js b/src/writeImportMapFile.js similarity index 97% rename from src/generateImportMapForProject.js rename to src/writeImportMapFile.js index 98727dde..ceb279bd 100644 --- a/src/generateImportMapForProject.js +++ b/src/writeImportMapFile.js @@ -7,7 +7,7 @@ import { import { composeTwoImportMaps } from "@jsenv/import-map" import { importMapToVsCodeConfigPaths } from "./internal/importMapToVsCodeConfigPaths.js" -export const generateImportMapForProject = async ( +export const writeImportMapFile = async ( importMapInputs = [], { projectDirectoryUrl, From f2eaac3a40cb4d1cb9c44732a6be84d6a2a0eea8 Mon Sep 17 00:00:00 2001 From: Damien Maillard Date: Fri, 12 Mar 2021 10:04:04 +0100 Subject: [PATCH 27/36] update import map file generation test --- .gitignore | 2 +- readme.md | 2 +- src/getImportMapFromFile.js | 2 +- .../writeImportMapFile.basic.test.js} | 4 ++-- 4 files changed, 5 insertions(+), 5 deletions(-) rename test/{generateImportMapForProject/generateImportMapForProject.basic.test.js => writeImportMapFile/writeImportMapFile.basic.test.js} (88%) diff --git a/.gitignore b/.gitignore index e88af1d2..c7ef431a 100644 --- a/.gitignore +++ b/.gitignore @@ -5,7 +5,7 @@ /docs/basic-project/package-lock.json /docs/basic-project/yarn.lock /node_modules/ -/test/generateImportMapForProject/**/*.importmap +/test/writeImportMapFile/**/*.importmap /import-map.importmap /jsconfig.json /package-lock.json diff --git a/readme.md b/readme.md index baa926eb..16e019b7 100644 --- a/readme.md +++ b/readme.md @@ -180,7 +180,7 @@ await writeImportMapFile(importMapInputs, { `importMapInputs` is an array of importmap object or promise resolving to importmap objects. This parameter is optional and is an empty array by default. -> When `importMapInputs` is empty a warning is emitted and `generateImportMapForProject` write an empty importmap file. +> When `importMapInputs` is empty a warning is emitted and `writeImportMapFile` write an empty importmap file. ## importMapFile diff --git a/src/getImportMapFromFile.js b/src/getImportMapFromFile.js index 502fc044..b92b2512 100644 --- a/src/getImportMapFromFile.js +++ b/src/getImportMapFromFile.js @@ -8,7 +8,7 @@ export const getImportMapFromFile = async ({ projectDirectoryUrl, importMapFileR const importmap = await readFile(importmapFileUrl, { as: "json" }) // ensure the importmap is now relative to the project directory url - // we do that because generateImportMapForProject expect all importmap + // we do that because writeImportMapFile expect all importmap // to be relative to the projectDirectoryUrl const importmapFakeRootUrl = resolveUrl("whatever.importmap", projectDirectoryUrl) const importmapRelativeToProject = moveImportMap( diff --git a/test/generateImportMapForProject/generateImportMapForProject.basic.test.js b/test/writeImportMapFile/writeImportMapFile.basic.test.js similarity index 88% rename from test/generateImportMapForProject/generateImportMapForProject.basic.test.js rename to test/writeImportMapFile/writeImportMapFile.basic.test.js index 387bb04e..632c0b36 100644 --- a/test/generateImportMapForProject/generateImportMapForProject.basic.test.js +++ b/test/writeImportMapFile/writeImportMapFile.basic.test.js @@ -1,12 +1,12 @@ import { assert } from "@jsenv/assert" import { resolveUrl, readFile } from "@jsenv/util" -import { generateImportMapForProject } from "../../index.js" +import { writeImportMapFile } from "@jsenv/node-module-import-map" const testDirectoryUrl = resolveUrl("./", import.meta.url) const importMapFileRelativeUrl = "test.importmap" const importMapFileUrl = resolveUrl(importMapFileRelativeUrl, testDirectoryUrl) -await generateImportMapForProject( +await writeImportMapFile( [ { imports: { foo: "./bar.js", bar: "./hello.js" }, From 95935ea017443f47124c002c9f458e93883f494a Mon Sep 17 00:00:00 2001 From: Damien Maillard Date: Fri, 12 Mar 2021 10:23:54 +0100 Subject: [PATCH 28/36] Add test for auto mapping in node modules + rename test directory --- .../from-js/getImportMapFromJsFiles.js | 9 ++- .../auto-bare-specifier.test.js | 48 +++++++++++++ .../auto-bare-specifier}/root/file.js | 0 .../auto-bare-specifier/root/index.js | 2 + .../auto-bare-specifier}/root/package.json | 0 .../auto-extension-node-module.test.js | 67 +++++++++++++++++++ .../auto-extension-node-module/root/main.js | 2 + .../root/node_modules/leftpad/file.js | 1 + .../root/node_modules/leftpad/index.js | 1 + .../root/node_modules/leftpad/other-file.ts | 0 .../root/node_modules/leftpad/package.json | 1 + .../root/package.json | 9 +++ .../auto-extension-project.test.js} | 0 .../auto-extension-project/root/file.js | 0 .../auto-extension-project}/root/index.js | 0 .../auto-extension-project/root/package.json | 3 + 16 files changed, 142 insertions(+), 1 deletion(-) create mode 100644 test/getImportMapFromProjectFiles/auto-mapping/auto-bare-specifier/auto-bare-specifier.test.js rename test/getImportMapFromProjectFiles/{from-js/extensionless-js => auto-mapping/auto-bare-specifier}/root/file.js (100%) create mode 100644 test/getImportMapFromProjectFiles/auto-mapping/auto-bare-specifier/root/index.js rename test/getImportMapFromProjectFiles/{from-js/extensionless-js => auto-mapping/auto-bare-specifier}/root/package.json (100%) create mode 100644 test/getImportMapFromProjectFiles/auto-mapping/auto-extension-node-module/auto-extension-node-module.test.js create mode 100644 test/getImportMapFromProjectFiles/auto-mapping/auto-extension-node-module/root/main.js create mode 100644 test/getImportMapFromProjectFiles/auto-mapping/auto-extension-node-module/root/node_modules/leftpad/file.js create mode 100644 test/getImportMapFromProjectFiles/auto-mapping/auto-extension-node-module/root/node_modules/leftpad/index.js create mode 100644 test/getImportMapFromProjectFiles/auto-mapping/auto-extension-node-module/root/node_modules/leftpad/other-file.ts create mode 100644 test/getImportMapFromProjectFiles/auto-mapping/auto-extension-node-module/root/node_modules/leftpad/package.json create mode 100644 test/getImportMapFromProjectFiles/auto-mapping/auto-extension-node-module/root/package.json rename test/getImportMapFromProjectFiles/{from-js/extensionless-js/extensionless-js.test.js => auto-mapping/auto-extension-project/auto-extension-project.test.js} (100%) create mode 100644 test/getImportMapFromProjectFiles/auto-mapping/auto-extension-project/root/file.js rename test/getImportMapFromProjectFiles/{from-js/extensionless-js => auto-mapping/auto-extension-project}/root/index.js (100%) create mode 100644 test/getImportMapFromProjectFiles/auto-mapping/auto-extension-project/root/package.json diff --git a/src/internal/from-js/getImportMapFromJsFiles.js b/src/internal/from-js/getImportMapFromJsFiles.js index 29c21a73..8c6fb279 100644 --- a/src/internal/from-js/getImportMapFromJsFiles.js +++ b/src/internal/from-js/getImportMapFromJsFiles.js @@ -75,6 +75,7 @@ export const getImportMapFromJsFiles = async ({ throw e } gotBareSpecifierError = true + fileUrl = resolveUrl(specifier, importer) } const fileUrlOnFileSystem = await resolveFile(fileUrl, { @@ -282,7 +283,13 @@ const mappingToImportmapString = ({ scope, from, to }) => { ) } -const mappingToExportsFieldString = ({ from, to }) => { +const mappingToExportsFieldString = ({ scope, from, to }) => { + if (scope) { + const scopeUrl = resolveUrl(scope, "file://") + const toUrl = resolveUrl(to, "file://") + to = `./${urlToRelativeUrl(toUrl, scopeUrl)}` + } + return JSON.stringify( { exports: { diff --git a/test/getImportMapFromProjectFiles/auto-mapping/auto-bare-specifier/auto-bare-specifier.test.js b/test/getImportMapFromProjectFiles/auto-mapping/auto-bare-specifier/auto-bare-specifier.test.js new file mode 100644 index 00000000..b59840bb --- /dev/null +++ b/test/getImportMapFromProjectFiles/auto-mapping/auto-bare-specifier/auto-bare-specifier.test.js @@ -0,0 +1,48 @@ +import { assert } from "@jsenv/assert" +import { resolveUrl } from "@jsenv/util" +import { getImportMapFromProjectFiles } from "@jsenv/node-module-import-map" + +const testDirectoryUrl = resolveUrl("./root/", import.meta.url) + +const warnings = [] +const importmap = await getImportMapFromProjectFiles({ + projectDirectoryUrl: testDirectoryUrl, + jsFiles: true, + onWarn: (warning) => { + warnings.push(warning) + }, +}) +const actual = { + warnings, + importmap, +} +const expected = { + warnings: [ + { + code: "AUTO_MAPPING", + message: `Auto mapping file to ./file.js. +--- specifier origin --- +${testDirectoryUrl}index.js:2:7 + 1 | // eslint-disable-next-line import/no-unresolved +> 2 | import "file" + | ^ + 3 |${" "} +--- suggestion --- +To get rid of this warning, add an explicit mapping into package.json. +{ + "exports": { + "file": "./file.js" + } +} +into ${testDirectoryUrl}package.json.`, + }, + ], + importmap: { + imports: { + file: "./file.js", + root: "./index.js", + }, + scopes: {}, + }, +} +assert({ actual, expected }) diff --git a/test/getImportMapFromProjectFiles/from-js/extensionless-js/root/file.js b/test/getImportMapFromProjectFiles/auto-mapping/auto-bare-specifier/root/file.js similarity index 100% rename from test/getImportMapFromProjectFiles/from-js/extensionless-js/root/file.js rename to test/getImportMapFromProjectFiles/auto-mapping/auto-bare-specifier/root/file.js diff --git a/test/getImportMapFromProjectFiles/auto-mapping/auto-bare-specifier/root/index.js b/test/getImportMapFromProjectFiles/auto-mapping/auto-bare-specifier/root/index.js new file mode 100644 index 00000000..21305e36 --- /dev/null +++ b/test/getImportMapFromProjectFiles/auto-mapping/auto-bare-specifier/root/index.js @@ -0,0 +1,2 @@ +// eslint-disable-next-line import/no-unresolved +import "file" diff --git a/test/getImportMapFromProjectFiles/from-js/extensionless-js/root/package.json b/test/getImportMapFromProjectFiles/auto-mapping/auto-bare-specifier/root/package.json similarity index 100% rename from test/getImportMapFromProjectFiles/from-js/extensionless-js/root/package.json rename to test/getImportMapFromProjectFiles/auto-mapping/auto-bare-specifier/root/package.json diff --git a/test/getImportMapFromProjectFiles/auto-mapping/auto-extension-node-module/auto-extension-node-module.test.js b/test/getImportMapFromProjectFiles/auto-mapping/auto-extension-node-module/auto-extension-node-module.test.js new file mode 100644 index 00000000..5869dc81 --- /dev/null +++ b/test/getImportMapFromProjectFiles/auto-mapping/auto-extension-node-module/auto-extension-node-module.test.js @@ -0,0 +1,67 @@ +import { assert } from "@jsenv/assert" +import { resolveUrl } from "@jsenv/util" +import { getImportMapFromProjectFiles } from "@jsenv/node-module-import-map" + +const testDirectoryUrl = resolveUrl("./root/", import.meta.url) + +const warnings = [] +const importmap = await getImportMapFromProjectFiles({ + projectDirectoryUrl: testDirectoryUrl, + jsFiles: true, + onWarn: (warning) => { + warnings.push(warning) + }, +}) +const actual = { + warnings, + importmap, +} +const expected = { + warnings: [ + { + code: "AUTO_MAPPING", + message: `Auto mapping ./file to ./node_modules/leftpad/file.js. +--- specifier origin --- +${testDirectoryUrl}node_modules/leftpad/index.js:1:7 +> 1 | import "./file" + | ^ +--- suggestion --- +To get rid of this warning, add an explicit mapping into package.json. +{ + "exports": { + "./file": "./file.js" + } +} +into ${testDirectoryUrl}node_modules/leftpad/package.json.`, + }, + { + code: "AUTO_MAPPING", + message: `Auto mapping ./other-file to ./node_modules/leftpad/other-file.ts. +--- specifier origin --- +${testDirectoryUrl}node_modules/leftpad/file.js:1:7 +> 1 | import "./other-file" + | ^ +--- suggestion --- +To get rid of this warning, add an explicit mapping into package.json. +{ + "exports": { + "./other-file": "./other-file.ts" + } +} +into ${testDirectoryUrl}node_modules/leftpad/package.json.`, + }, + ], + importmap: { + imports: { + leftpad: "./node_modules/leftpad/index.js", + root: "./main.js", + }, + scopes: { + "./node_modules/leftpad/": { + "./other-file": "./node_modules/leftpad/other-file.ts", + "./file": "./node_modules/leftpad/file.js", + }, + }, + }, +} +assert({ actual, expected }) diff --git a/test/getImportMapFromProjectFiles/auto-mapping/auto-extension-node-module/root/main.js b/test/getImportMapFromProjectFiles/auto-mapping/auto-extension-node-module/root/main.js new file mode 100644 index 00000000..7cd7ba94 --- /dev/null +++ b/test/getImportMapFromProjectFiles/auto-mapping/auto-extension-node-module/root/main.js @@ -0,0 +1,2 @@ +// eslint-disable-next-line import/no-unresolved +import "leftpad" diff --git a/test/getImportMapFromProjectFiles/auto-mapping/auto-extension-node-module/root/node_modules/leftpad/file.js b/test/getImportMapFromProjectFiles/auto-mapping/auto-extension-node-module/root/node_modules/leftpad/file.js new file mode 100644 index 00000000..68b0fdfe --- /dev/null +++ b/test/getImportMapFromProjectFiles/auto-mapping/auto-extension-node-module/root/node_modules/leftpad/file.js @@ -0,0 +1 @@ +import "./other-file" \ No newline at end of file diff --git a/test/getImportMapFromProjectFiles/auto-mapping/auto-extension-node-module/root/node_modules/leftpad/index.js b/test/getImportMapFromProjectFiles/auto-mapping/auto-extension-node-module/root/node_modules/leftpad/index.js new file mode 100644 index 00000000..78dfb1b2 --- /dev/null +++ b/test/getImportMapFromProjectFiles/auto-mapping/auto-extension-node-module/root/node_modules/leftpad/index.js @@ -0,0 +1 @@ +import "./file" \ No newline at end of file diff --git a/test/getImportMapFromProjectFiles/auto-mapping/auto-extension-node-module/root/node_modules/leftpad/other-file.ts b/test/getImportMapFromProjectFiles/auto-mapping/auto-extension-node-module/root/node_modules/leftpad/other-file.ts new file mode 100644 index 00000000..e69de29b diff --git a/test/getImportMapFromProjectFiles/auto-mapping/auto-extension-node-module/root/node_modules/leftpad/package.json b/test/getImportMapFromProjectFiles/auto-mapping/auto-extension-node-module/root/node_modules/leftpad/package.json new file mode 100644 index 00000000..9e26dfee --- /dev/null +++ b/test/getImportMapFromProjectFiles/auto-mapping/auto-extension-node-module/root/node_modules/leftpad/package.json @@ -0,0 +1 @@ +{} \ No newline at end of file diff --git a/test/getImportMapFromProjectFiles/auto-mapping/auto-extension-node-module/root/package.json b/test/getImportMapFromProjectFiles/auto-mapping/auto-extension-node-module/root/package.json new file mode 100644 index 00000000..f97e5fca --- /dev/null +++ b/test/getImportMapFromProjectFiles/auto-mapping/auto-extension-node-module/root/package.json @@ -0,0 +1,9 @@ +{ + "name": "root", + "type": "module", + "module": "main.js", + "main": "main.cjs", + "dependencies": { + "leftpad": "*" + } +} diff --git a/test/getImportMapFromProjectFiles/from-js/extensionless-js/extensionless-js.test.js b/test/getImportMapFromProjectFiles/auto-mapping/auto-extension-project/auto-extension-project.test.js similarity index 100% rename from test/getImportMapFromProjectFiles/from-js/extensionless-js/extensionless-js.test.js rename to test/getImportMapFromProjectFiles/auto-mapping/auto-extension-project/auto-extension-project.test.js diff --git a/test/getImportMapFromProjectFiles/auto-mapping/auto-extension-project/root/file.js b/test/getImportMapFromProjectFiles/auto-mapping/auto-extension-project/root/file.js new file mode 100644 index 00000000..e69de29b diff --git a/test/getImportMapFromProjectFiles/from-js/extensionless-js/root/index.js b/test/getImportMapFromProjectFiles/auto-mapping/auto-extension-project/root/index.js similarity index 100% rename from test/getImportMapFromProjectFiles/from-js/extensionless-js/root/index.js rename to test/getImportMapFromProjectFiles/auto-mapping/auto-extension-project/root/index.js diff --git a/test/getImportMapFromProjectFiles/auto-mapping/auto-extension-project/root/package.json b/test/getImportMapFromProjectFiles/auto-mapping/auto-extension-project/root/package.json new file mode 100644 index 00000000..7636edf1 --- /dev/null +++ b/test/getImportMapFromProjectFiles/auto-mapping/auto-extension-project/root/package.json @@ -0,0 +1,3 @@ +{ + "name": "root" +} From 6a1e1f75b90af0239931b3ac480a8d43cff2bb67 Mon Sep 17 00:00:00 2001 From: Damien Maillard Date: Fri, 12 Mar 2021 11:31:12 +0100 Subject: [PATCH 29/36] - handle browser field being an object - Enable js file parsing by default - Update tests - update dist --- dist/commonjs/main.cjs | 1914 ++++++++++++----- dist/commonjs/main.cjs.map | 468 ++-- package.json | 2 +- src/getImportMapFromProjectFiles.js | 2 +- .../from-js/getImportMapFromJsFiles.js | 5 + .../getImportMapFromPackageFiles.js | 111 +- .../from-package/node-module-resolution.js | 5 +- .../from-package/resolvePackageMain.js | 11 +- .../core/issue-20/issue-20.test.js | 1 - .../core/issue-20/root/package.json | 1 + .../malformed-dependency-package.test.js | 19 +- .../root/package.json | 1 + .../optional-dependency.test.js | 20 +- .../core/optional-dependency/root/index.js | 0 .../core/shared-indirect/root/package.json | 1 + .../shared-indirect/shared-indirect.test.js | 1 - .../core/shared/root/package.json | 1 + .../core/shared/shared.test.js | 1 - .../included-predicate.test.js | 1 - .../included-predicate/root/package.json | 1 + .../exports-pattern-directory.test.js | 2 +- .../exports-pattern-directory/root/index.js | 0 .../exports-pattern-extensionless.test.js | 36 +- .../root/index.js | 0 .../exports-sugar-conditional/root/index | 0 .../main-directory/root/index | 0 .../self-import/self-import-5/root/index | 0 .../root/node_modules/@jsenv/core/index | 0 .../self-import/self-import-6/root/index.js | 0 .../self-import-6/self-import-6.test.js | 3 - 30 files changed, 1859 insertions(+), 748 deletions(-) create mode 100644 test/getImportMapFromProjectFiles/core/optional-dependency/root/index.js create mode 100644 test/getImportMapFromProjectFiles/package-exports-field/exports-pattern-directory/root/index.js create mode 100644 test/getImportMapFromProjectFiles/package-exports-field/exports-pattern-extensionless/root/index.js create mode 100644 test/getImportMapFromProjectFiles/package-exports-field/exports-sugar-conditional/root/index create mode 100644 test/getImportMapFromProjectFiles/package-main-field/main-directory/root/index create mode 100644 test/getImportMapFromProjectFiles/self-import/self-import-5/root/index create mode 100644 test/getImportMapFromProjectFiles/self-import/self-import-5/root/node_modules/@jsenv/core/index create mode 100644 test/getImportMapFromProjectFiles/self-import/self-import-6/root/index.js diff --git a/dist/commonjs/main.cjs b/dist/commonjs/main.cjs index 20f1c4ae..b025b3e2 100644 --- a/dist/commonjs/main.cjs +++ b/dist/commonjs/main.cjs @@ -2,11 +2,406 @@ Object.defineProperty(exports, '__esModule', { value: true }); -var logger = require('@jsenv/logger'); var importMap = require('@jsenv/import-map'); +var logger = require('@jsenv/logger'); var util = require('@jsenv/util'); +var module$1 = require('module'); var cancellation = require('@jsenv/cancellation'); +const memoizeAsyncFunctionByUrl = fn => { + const cache = {}; + return memoizeAsyncFunction(fn, { + getMemoryEntryFromArguments: ([url]) => { + return { + get: () => { + return cache[url]; + }, + set: promise => { + cache[url] = promise; + }, + delete: () => { + delete cache[url]; + } + }; + } + }); +}; +const memoizeAsyncFunctionBySpecifierAndImporter = fn => { + const importerCache = {}; + return memoizeAsyncFunction(fn, { + getMemoryEntryFromArguments: ([specifier, importer]) => { + return { + get: () => { + const specifierCacheForImporter = importerCache[importer]; + return specifierCacheForImporter ? specifierCacheForImporter[specifier] : null; + }, + set: promise => { + const specifierCacheForImporter = importerCache[importer]; + + if (specifierCacheForImporter) { + specifierCacheForImporter[specifier] = promise; + } else { + importerCache[importer] = { + [specifier]: promise + }; + } + }, + delete: () => { + const specifierCacheForImporter = importerCache[importer]; + + if (specifierCacheForImporter) { + delete specifierCacheForImporter[specifier]; + } + } + }; + } + }); +}; + +const memoizeAsyncFunction = (fn, { + getMemoryEntryFromArguments +}) => { + return async (...args) => { + const memoryEntry = getMemoryEntryFromArguments(args); + const promiseFromMemory = memoryEntry.get(); + + if (promiseFromMemory) { + return promiseFromMemory; + } + + let _resolve; + + let _reject; + + const promise = new Promise((resolve, reject) => { + _resolve = resolve; + _reject = reject; + }); + memoryEntry.set(promise); + let value; + let error; + + try { + value = fn(...args); + error = false; + } catch (e) { + value = e; + error = true; + memoryEntry.delete(); + } + + if (error) { + _reject(error); + } else { + _resolve(value); + } + + return promise; + }; +}; + +/* global __filename */ +const filenameContainsBackSlashes = __filename.indexOf("\\") > -1; +const url = filenameContainsBackSlashes ? `file:///${__filename.replace(/\\/g, "/")}` : `file://${__filename}`; + +const require$1 = module$1.createRequire(url); + +const parser = require$1("@babel/parser"); + +const traverse = require$1("@babel/traverse"); + +const parseSpecifiersFromFile = async (fileUrl, { + fileContent, + sourceType = "module", + allowImportExportEverywhere = true, + allowAwaitOutsideFunction = true, + ranges = true, + jsx = true, + typescript = true, + flow = false, + ...options +} = {}) => { + fileContent = fileContent === undefined ? await util.readFile(fileUrl, { + as: "string" + }) : fileContent; + const ast = parser.parse(fileContent, { + sourceType, + sourceFilename: util.urlToFileSystemPath(fileUrl), + allowImportExportEverywhere, + allowAwaitOutsideFunction, + ranges, + plugins: [// "estree", + "topLevelAwait", "exportDefaultFrom", ...(jsx ? ["jsx"] : []), ...(typescript ? ["typescript"] : []), ...(flow ? ["jsx"] : [])], + ...options + }); + const specifiers = {}; + + const addSpecifier = ({ + path, + type + }) => { + const specifier = path.node.value; + specifiers[specifier] = { + line: path.node.loc.start.line, + column: path.node.loc.start.column, + type + }; + }; + + traverse.default(ast, { + // ImportExpression: (path) => { + // if (path.node.arguments[0].type !== "StringLiteral") { + // // Non-string argument, probably a variable or expression, e.g. + // // import(moduleId) + // // import('./' + moduleName) + // return + // } + // addSpecifier(path.get("arguments")[0]) + // }, + CallExpression: path => { + if (path.node.callee.type !== "Import") { + // Some other function call, not import(); + return; + } + + if (path.node.arguments[0].type !== "StringLiteral") { + // Non-string argument, probably a variable or expression, e.g. + // import(moduleId) + // import('./' + moduleName) + return; + } + + addSpecifier({ + path: path.get("arguments")[0], + type: "import-dynamic" + }); + }, + ExportAllDeclaration: path => { + addSpecifier({ + path: path.get("source"), + type: "export-all" + }); + }, + ExportNamedDeclaration: path => { + if (!path.node.source) { + // This export has no "source", so it's probably + // a local variable or function, e.g. + // export { varName } + // export const constName = ... + // export function funcName() {} + return; + } + + addSpecifier({ + path: path.get("source"), + type: "export-named" + }); + }, + ImportDeclaration: path => { + addSpecifier({ + path: path.get("source"), + type: "import-static" + }); + } + }); + return specifiers; +}; + +// https://github.com/postcss/postcss/blob/fd30d3df5abc0954a0ec642a3cdc644ab2aacf9c/lib/css-syntax-error.js#L43 +// https://github.com/postcss/postcss/blob/fd30d3df5abc0954a0ec642a3cdc644ab2aacf9c/lib/terminal-highlight.js#L50 +// https://github.com/babel/babel/blob/eea156b2cb8deecfcf82d52aa1b71ba4995c7d68/packages/babel-code-frame/src/index.js#L1 +const showSource = ({ + url, + line, + column, + source +}) => { + let message = ""; + message += typeof url === "undefined" ? "Anonymous" : url; + + if (typeof line !== "number") { + return message; + } + + message += `:${line}`; + + if (typeof column === "number") { + message += `:${column}`; + } + + if (!source) { + return message; + } + + return `${message} +${showSourceLocation(source, { + line, + column + })}`; +}; +const red = "\x1b[31m"; +const grey = "\x1b[39m"; +const ansiResetSequence = "\x1b[0m"; + +const showSourceLocation = (source, { + line, + column, + numberOfSurroundingLinesToShow = 1, + lineMaxLength = 120, + color = false, + markColor = red, + asideColor = grey, + colorMark = string => `${markColor}${string}${ansiResetSequence}`, + colorAside = string => `${asideColor}${string}${ansiResetSequence}` +}) => { + const mark = color ? colorMark : string => string; + const aside = color ? colorAside : string => string; + const lines = source.split(/\r?\n/); + let lineRange = { + start: line - 1, + end: line + }; + lineRange = moveLineRangeUp(lineRange, numberOfSurroundingLinesToShow); + lineRange = moveLineRangeDown(lineRange, numberOfSurroundingLinesToShow); + lineRange = lineRangeWithinLines(lineRange, lines); + const linesToShow = lines.slice(lineRange.start, lineRange.end); + const endLineNumber = lineRange.end; + const lineNumberMaxWidth = String(endLineNumber).length; + const columnRange = {}; + + if (column === undefined) { + columnRange.start = 0; + columnRange.end = lineMaxLength; + } else if (column > lineMaxLength) { + columnRange.start = column - Math.floor(lineMaxLength / 2); + columnRange.end = column + Math.ceil(lineMaxLength / 2); + } else { + columnRange.start = 0; + columnRange.end = lineMaxLength; + } + + return linesToShow.map((lineSource, index) => { + const lineNumber = lineRange.start + index + 1; + const isMainLine = lineNumber === line; + const lineSourceTruncated = applyColumnRange(columnRange, lineSource); + const lineNumberWidth = String(lineNumber).length; // ensure if line moves from 7,8,9 to 10 the display is still great + + const lineNumberRightSpacing = " ".repeat(lineNumberMaxWidth - lineNumberWidth); + const asideSource = `${lineNumber}${lineNumberRightSpacing} |`; + const lineFormatted = `${aside(asideSource)} ${lineSourceTruncated}`; + + if (isMainLine) { + if (column === undefined) { + return `${mark(">")} ${lineFormatted}`; + } + + const lineSourceUntilColumn = lineSourceTruncated.slice(0, column - columnRange.start); + const spacing = stringToSpaces(lineSourceUntilColumn); + const mainLineFormatted = `${mark(">")} ${lineFormatted} + ${" ".repeat(lineNumberWidth)} ${aside("|")}${spacing}${mark("^")}`; + return mainLineFormatted; + } + + return ` ${lineFormatted}`; + }).join(` +`); +}; + +const applyColumnRange = ({ + start, + end +}, line) => { + if (typeof start !== "number") { + throw new TypeError(`start must be a number, received ${start}`); + } + + if (typeof end !== "number") { + throw new TypeError(`end must be a number, received ${end}`); + } + + if (end < start) { + throw new Error(`end must be greater than start, but ${end} is smaller than ${start}`); + } + + const prefix = "…"; + const suffix = "…"; + const lastIndex = line.length; + + if (line.length === 0) { + // don't show any ellipsis if the line is empty + // because it's not truncated in that case + return ""; + } + + const startTruncated = start > 0; + const endTruncated = lastIndex > end; + let from = startTruncated ? start + prefix.length : start; + let to = endTruncated ? end - suffix.length : end; + if (to > lastIndex) to = lastIndex; + + if (start >= lastIndex || from === to) { + return ""; + } + + let result = ""; + + while (from < to) { + result += line[from]; + from++; + } + + if (result.length === 0) { + return ""; + } + + if (startTruncated && endTruncated) { + return `${prefix}${result}${suffix}`; + } + + if (startTruncated) { + return `${prefix}${result}`; + } + + if (endTruncated) { + return `${result}${suffix}`; + } + + return result; +}; + +const stringToSpaces = string => string.replace(/[^\t]/g, " "); // const getLineRangeLength = ({ start, end }) => end - start + + +const moveLineRangeUp = ({ + start, + end +}, number) => { + return { + start: start - number, + end + }; +}; + +const moveLineRangeDown = ({ + start, + end +}, number) => { + return { + start, + end: end + number + }; +}; + +const lineRangeWithinLines = ({ + start, + end +}, lines) => { + return { + start: start < 0 ? 0 : start, + end: end > lines.length ? lines.length : end + }; +}; + const resolveFile = async (fileUrl, { magicExtensions }) => { @@ -28,7 +423,7 @@ const resolveFile = async (fileUrl, { return null; } - return `${indexFileUrl}.${extensionLeadingToAFile}`; + return `${indexFileUrl}${extensionLeadingToAFile}`; } // file not found and it has an extension @@ -45,17 +440,17 @@ const resolveFile = async (fileUrl, { } // magic extension worked - return `${fileUrl}.${extensionLeadingToAFile}`; + return `${fileUrl}${extensionLeadingToAFile}`; }; const findExtensionLeadingToFile = async (fileUrl, magicExtensions) => { - const fileDirectoryUrl = util.resolveUrl("./", fileUrl); - const fileBasename = util.urlToBasename(fileUrl); + const urlDirectoryUrl = util.resolveUrl("./", fileUrl); + const urlFilename = util.urlToFilename(fileUrl); const extensionLeadingToFile = await cancellation.firstOperationMatching({ array: magicExtensions, start: async extensionCandidate => { - const filePathCandidate = `${fileDirectoryUrl}/${fileBasename}.${extensionCandidate}`; - const stats = await util.readFileSystemNodeStat(filePathCandidate, { + const urlCandidate = `${urlDirectoryUrl}${urlFilename}${extensionCandidate}`; + const stats = await util.readFileSystemNodeStat(urlCandidate, { nullIfNotFound: true }); return stats && stats.isFile() ? extensionCandidate : null; @@ -65,33 +460,387 @@ const findExtensionLeadingToFile = async (fileUrl, magicExtensions) => { return extensionLeadingToFile || null; }; -const magicExtensions = ["js", "json", "node"]; +const BARE_SPECIFIER_ERROR = {}; +const getImportMapFromJsFiles = async ({ + warn, + importMap: importMap$1, + projectDirectoryUrl, + removeUnusedMappings, + magicExtensions = [".js", ".jsx", ".ts", ".tsx", ".node", ".json"] +}) => { + const projectPackageFileUrl = util.resolveUrl("./package.json", projectDirectoryUrl); + const imports = {}; + const scopes = {}; + + const addMapping = ({ + scope, + from, + to + }) => { + if (scope) { + scopes[scope] = { ...(scopes[scope] || {}), + [from]: to + }; + } else { + imports[from] = to; + } + }; + + const topLevelMappingsUsed = []; + const scopedMappingsUsed = {}; + + const markMappingAsUsed = ({ + scope, + from, + to + }) => { + if (scope) { + if (scope in scopedMappingsUsed) { + scopedMappingsUsed[scope].push({ + from, + to + }); + } else { + scopedMappingsUsed[scope] = [{ + from, + to + }]; + } + } else { + topLevelMappingsUsed.push({ + from, + to + }); + } + }; + + const importMapNormalized = importMap.normalizeImportMap(importMap$1, projectDirectoryUrl); + + const trackAndResolveImport = (specifier, importer) => { + return importMap.resolveImport({ + specifier, + importer, + importMap: importMapNormalized, + defaultExtension: false, + onImportMapping: ({ + scope, + from + }) => { + markMappingAsUsed({ + scope, + from, + to: scope ? importMap$1.scopes[scope][from] : importMap$1.imports[from] + }); + }, + createBareSpecifierError: () => BARE_SPECIFIER_ERROR + }); + }; + + const visitFile = async (specifier, importer, { + importedBy + }) => { + let fileUrl; + let gotBareSpecifierError = false; + + try { + fileUrl = trackAndResolveImport(specifier, importer); + } catch (e) { + if (e !== BARE_SPECIFIER_ERROR) { + throw e; + } + + gotBareSpecifierError = true; + fileUrl = util.resolveUrl(specifier, importer); + } + + const fileUrlOnFileSystem = await resolveFile(fileUrl, { + magicExtensions: magicExtensionWithImporterExtension(magicExtensions, importer) + }); + + if (!fileUrlOnFileSystem) { + warn(createFileNotFoundWarning({ + specifier, + importedBy, + fileUrl, + magicExtensions + })); + return; + } + + const needsAutoMapping = fileUrlOnFileSystem !== fileUrl || gotBareSpecifierError; + + if (needsAutoMapping) { + const packageDirectoryUrl = packageDirectoryUrlFromUrl(fileUrl, projectDirectoryUrl); + const packageFileUrl = util.resolveUrl("package.json", packageDirectoryUrl); + const autoMapping = { + scope: packageFileUrl === projectPackageFileUrl ? undefined : `./${util.urlToRelativeUrl(packageDirectoryUrl, projectDirectoryUrl)}`, + from: specifier, + to: `./${util.urlToRelativeUrl(fileUrlOnFileSystem, projectDirectoryUrl)}` + }; + addMapping(autoMapping); + markMappingAsUsed(autoMapping); + warn(formatAutoMappingSpecifierWarning({ + specifier, + importedBy, + autoMapping, + closestPackageDirectoryUrl: packageDirectoryUrl, + closestPackageObject: await util.readFile(packageFileUrl, { + as: "json" + }) + })); + } + + const fileContent = await readFileContent(fileUrlOnFileSystem); + const specifiers = await parseSpecifiersFromFile(fileUrlOnFileSystem, { + fileContent + }); + await Promise.all(Object.keys(specifiers).map(async specifier => { + const specifierInfo = specifiers[specifier]; + await visitFileMemoized(specifier, fileUrlOnFileSystem, { + importedBy: showSource({ + url: fileUrlOnFileSystem, + line: specifierInfo.line, + column: specifierInfo.column, + source: fileContent + }) + }); + })); + }; + + const visitFileMemoized = memoizeAsyncFunctionBySpecifierAndImporter(visitFile); + const readFileContent = memoizeAsyncFunctionByUrl(fileUrl => { + return util.readFile(fileUrl, { + as: "string" + }); + }); + const projectPackageObject = await util.readFile(projectPackageFileUrl, { + as: "json" + }); + await visitFileMemoized(projectPackageObject.name, projectPackageFileUrl, { + importedBy: projectPackageObject.exports ? `${projectPackageFileUrl}#exports` : `${projectPackageFileUrl}` + }); + + if (removeUnusedMappings) { + const importsUsed = {}; + topLevelMappingsUsed.forEach(({ + from, + to + }) => { + importsUsed[from] = to; + }); + const scopesUsed = {}; + Object.keys(scopedMappingsUsed).forEach(scope => { + const mappingsUsed = scopedMappingsUsed[scope]; + const scopedMappings = {}; + mappingsUsed.forEach(({ + from, + to + }) => { + scopedMappings[from] = to; + }); + scopesUsed[scope] = scopedMappings; + }); + return { + imports: importsUsed, + scopes: scopesUsed + }; + } + + return { + imports, + scopes + }; +}; + +const packageDirectoryUrlFromUrl = (url, projectDirectoryUrl) => { + const relativeUrl = util.urlToRelativeUrl(url, projectDirectoryUrl); + const lastNodeModulesDirectoryStartIndex = relativeUrl.lastIndexOf("node_modules/"); + + if (lastNodeModulesDirectoryStartIndex === -1) { + return projectDirectoryUrl; + } + + const lastNodeModulesDirectoryEndIndex = lastNodeModulesDirectoryStartIndex + `node_modules/`.length; + const beforeNodeModulesLastDirectory = relativeUrl.slice(0, lastNodeModulesDirectoryEndIndex); + const afterLastNodeModulesDirectory = relativeUrl.slice(lastNodeModulesDirectoryEndIndex); + const remainingDirectories = afterLastNodeModulesDirectory.split("/"); + + if (afterLastNodeModulesDirectory[0] === "@") { + // scoped package + return `${projectDirectoryUrl}${beforeNodeModulesLastDirectory}${remainingDirectories.slice(0, 2).join("/")}`; + } + + return `${projectDirectoryUrl}${beforeNodeModulesLastDirectory}${remainingDirectories[0]}/`; +}; + +const magicExtensionWithImporterExtension = (magicExtensions, importer) => { + const importerExtension = util.urlToExtension(importer); + const magicExtensionsWithoutImporterExtension = magicExtensions.filter(ext => ext !== importerExtension); + return [importerExtension, ...magicExtensionsWithoutImporterExtension]; +}; + +const createFileNotFoundWarning = ({ + specifier, + importedBy, + fileUrl, + magicExtensions +}) => { + return { + code: "FILE_NOT_FOUND", + message: logger.createDetailedMessage(`Cannot find file for "${specifier}"`, { + "specifier origin": importedBy, + "file url tried": fileUrl, + ...(util.urlToExtension(fileUrl) === "" ? { + ["extensions tried"]: magicExtensions.join(`, `) + } : {}) + }) + }; +}; + +const formatAutoMappingSpecifierWarning = ({ + importedBy, + autoMapping, + closestPackageDirectoryUrl, + closestPackageObject +}) => { + return { + code: "AUTO_MAPPING", + message: logger.createDetailedMessage(`Auto mapping ${autoMapping.from} to ${autoMapping.to}.`, { + "specifier origin": importedBy, + "suggestion": decideAutoMappingSuggestion({ + autoMapping, + closestPackageDirectoryUrl, + closestPackageObject + }) + }) + }; +}; + +const decideAutoMappingSuggestion = ({ + autoMapping, + closestPackageDirectoryUrl, + closestPackageObject +}) => { + if (typeof closestPackageObject.importmap === "string") { + const packageImportmapFileUrl = util.resolveUrl(closestPackageObject.importmap, closestPackageDirectoryUrl); + return `To get rid of this warning, add an explicit mapping into importmap file. +${mappingToImportmapString(autoMapping)} +into ${packageImportmapFileUrl}.`; + } + + return `To get rid of this warning, add an explicit mapping into package.json. +${mappingToExportsFieldString(autoMapping)} +into ${closestPackageDirectoryUrl}package.json.`; +}; + +const mappingToImportmapString = ({ + scope, + from, + to +}) => { + if (scope) { + return JSON.stringify({ + scopes: { + [scope]: { + [from]: to + } + } + }, null, " "); + } + + return JSON.stringify({ + imports: { + [from]: to + } + }, null, " "); +}; + +const mappingToExportsFieldString = ({ + scope, + from, + to +}) => { + if (scope) { + const scopeUrl = util.resolveUrl(scope, "file://"); + const toUrl = util.resolveUrl(to, "file://"); + to = `./${util.urlToRelativeUrl(toUrl, scopeUrl)}`; + } + + return JSON.stringify({ + exports: { + [from]: to + } + }, null, " "); +}; + +const optimizeImportMap = ({ + imports, + scopes +}) => { + // remove useless duplicates (scoped key+value already defined on imports) + const scopesOptimized = {}; + Object.keys(scopes).forEach(scope => { + const scopeMappings = scopes[scope]; + const scopeMappingsOptimized = {}; + Object.keys(scopeMappings).forEach(mappingKey => { + const topLevelMappingValue = imports[mappingKey]; + const mappingValue = scopeMappings[mappingKey]; + + if (!topLevelMappingValue || topLevelMappingValue !== mappingValue) { + scopeMappingsOptimized[mappingKey] = mappingValue; + } + }); + + if (Object.keys(scopeMappingsOptimized).length > 0) { + scopesOptimized[scope] = scopeMappingsOptimized; + } + }); + return { + imports, + scopes: scopesOptimized + }; +}; + +const magicExtensions = [".js", ".json", ".node"]; const resolvePackageMain = ({ - logger, + warn, + packagesExportsPreference, packageFileUrl, packageJsonObject }) => { - if ("module" in packageJsonObject) { + if (packagesExportsPreference.includes("import") && "module" in packageJsonObject) { return resolveMainFile({ - logger, + warn, packageFileUrl, packageMainFieldName: "module", packageMainFieldValue: packageJsonObject.module }); } - if ("jsnext:main" in packageJsonObject) { + if (packagesExportsPreference.includes("import") && "jsnext:main" in packageJsonObject) { return resolveMainFile({ - logger, + warn, packageFileUrl, packageMainFieldName: "jsnext:main", packageMainFieldValue: packageJsonObject["jsnext:main"] }); } + if (packagesExportsPreference.includes("browser") && "browser" in packageJsonObject && // when it's an object it means some files + // should be replaced with an other, let's ignore this when we are searching + // for the main file + typeof packageJsonObject.browser === "string") { + return resolveMainFile({ + warn, + packageFileUrl, + packageMainFieldName: "browser", + packageMainFieldValue: packageJsonObject.browser + }); + } + if ("main" in packageJsonObject) { return resolveMainFile({ - logger, + warn, packageFileUrl, packageMainFieldName: "main", packageMainFieldValue: packageJsonObject.main @@ -99,7 +848,7 @@ const resolvePackageMain = ({ } return resolveMainFile({ - logger, + warn, packageFileUrl, packageMainFieldName: "default", packageMainFieldValue: "index" @@ -107,7 +856,7 @@ const resolvePackageMain = ({ }; const resolveMainFile = async ({ - logger, + warn, packageFileUrl, packageMainFieldName, packageMainFieldValue @@ -118,19 +867,16 @@ const resolveMainFile = async ({ return null; } - const packageFilePath = util.urlToFileSystemPath(packageFileUrl); const packageDirectoryUrl = util.resolveUrl("./", packageFileUrl); const mainFileRelativeUrl = packageMainFieldValue.endsWith("/") ? `${packageMainFieldValue}index` : packageMainFieldValue; const mainFileUrlFirstCandidate = util.resolveUrl(mainFileRelativeUrl, packageFileUrl); if (!mainFileUrlFirstCandidate.startsWith(packageDirectoryUrl)) { - logger.warn(` -${packageMainFieldName} field in package.json must be inside package.json folder. ---- ${packageMainFieldName} --- -${packageMainFieldValue} ---- package.json path --- -${packageFilePath} -`); + warn(createPackageMainFileMustBeRelativeWarning({ + packageMainFieldName, + packageMainFieldValue, + packageFileUrl + })); return null; } @@ -146,7 +892,7 @@ ${packageFilePath} // otherwise the package.json is missing the main field // it certainly means it's not important if (packageMainFieldName !== "default") { - logger.warn(formatFileNotFoundLog({ + warn(createPackageMainFileNotFoundWarning({ specifier: packageMainFieldValue, importedIn: `${packageFileUrl}#${packageMainFieldName}`, fileUrl: mainFileUrlFirstCandidate, @@ -160,19 +906,81 @@ ${packageFilePath} return mainFileUrl; }; -const formatFileNotFoundLog = ({ +const createPackageMainFileMustBeRelativeWarning = ({ + packageMainFieldName, + packageMainFieldValue, + packageFileUrl +}) => { + return { + code: "PACKAGE_MAIN_FILE_MUST_BE_RELATIVE", + message: `${packageMainFieldName} field in package.json must be inside package.json folder. +--- ${packageMainFieldName} --- +${packageMainFieldValue} +--- package.json path --- +${util.urlToFileSystemPath(packageFileUrl)}` + }; +}; + +const createPackageMainFileNotFoundWarning = ({ specifier, importedIn, fileUrl, magicExtensions }) => { - return logger.createDetailedMessage(`Cannot find file for "${specifier}"`, { - "imported in": importedIn, - "file url": fileUrl, - ...(util.urlToExtension(fileUrl) === "" ? { - ["extensions tried"]: magicExtensions.join(`,`) - } : {}) - }); + return { + code: "PACKAGE_MAIN_FILE_NOT_FOUND", + message: logger.createDetailedMessage(`Cannot find file for "${specifier}"`, { + "imported in": importedIn, + "file url tried": fileUrl, + ...(util.urlToExtension(fileUrl) === "" ? { + ["extensions tried"]: magicExtensions.join(`, `) + } : {}) + }) + }; +}; + +const visitPackageImportMap = async ({ + warn, + packageFileUrl, + packageJsonObject, + packageImportmap = packageJsonObject.importmap, + projectDirectoryUrl +}) => { + if (typeof packageImportmap === "undefined") { + return {}; + } + + if (typeof packageImportmap === "string") { + const importmapFileUrl = importMap.resolveUrl(packageImportmap, packageFileUrl); + const importmap = await util.readFile(importmapFileUrl, { + as: "json" + }); + return importMap.moveImportMap(importmap, importmapFileUrl, projectDirectoryUrl); + } + + if (typeof packageImportmap === "object" && packageImportmap !== null) { + return packageImportmap; + } + + warn(createPackageImportMapUnexpectedWarning({ + packageImportmap, + packageFileUrl + })); + return {}; +}; + +const createPackageImportMapUnexpectedWarning = ({ + packageImportmap, + packageFileUrl +}) => { + return { + code: "PACKAGE_IMPORTMAP_UNEXPECTED", + message: `unexpected value in package.json importmap field: value must be a string or an object. +--- value --- +${packageImportmap} +--- package.json path --- +${util.urlToFileSystemPath(packageFileUrl)}` + }; }; const specifierIsRelative = specifier => { @@ -192,233 +1000,164 @@ const specifierIsRelative = specifier => { return true; }; -const visitPackageImports = ({ - logger, +// https://nodejs.org/dist/latest-v13.x/docs/api/esm.html#esm_package_exports +const visitPackageExports = ({ + warn, packageFileUrl, - packageJsonObject + packageJsonObject, + packageExports = packageJsonObject.exports, + packageName = packageJsonObject.name, + projectDirectoryUrl, + packagesExportsPreference, + onExport }) => { - const importsForPackageImports = {}; - const packageFilePath = util.urlToFileSystemPath(packageFileUrl); - const { - imports: packageImports - } = packageJsonObject; - - if (typeof packageImports !== "object" || packageImports === null) { - logger.warn(` -imports of package.json must be an object. ---- package.json imports --- -${packageImports} ---- package.json path --- -${packageFilePath} -`); - return importsForPackageImports; - } - - Object.keys(packageImports).forEach(specifier => { - if (!specifierIsRelative(specifier)) { - logger.warn(` -found unexpected specifier in imports of package.json, it must be relative to package.json. ---- specifier --- -${specifier} ---- package.json path --- -${packageFilePath} -`); - return; - } - - const address = packageImports[specifier]; - - if (typeof address !== "string") { - logger.warn(` -found unexpected address in imports of package.json, it must be a string. ---- address --- -${address} ---- specifier --- -${specifier} ---- package.json path --- -${packageFilePath} -`); - return; - } + const packageDirectoryUrl = util.resolveUrl("./", packageFileUrl); + const packageDirectoryRelativeUrl = util.urlToRelativeUrl(packageDirectoryUrl, projectDirectoryUrl); + visitExportsSubpath(packageExports, packagesExportsPreference, { + onUnexpectedPackageExports: ({ + packageExportsValue, + packageExportsValuePath + }) => { + warn(createExportsValueWarning({ + packageExportsValue, + packageExportsValuePath, + packageFileUrl + })); + }, + onMixedPackageExports: ({ + packageExportsValue, + packageExportsValuePath + }) => { + // see https://nodejs.org/dist/latest-v13.x/docs/api/esm.html#esm_exports_sugar + warn(createExportsMixedWarning({ + packageExportsValue, + packageExportsValuePath, + packageFileUrl + })); + }, + onSubpathPackageExport: ({ + key, + value, + valuePath + }) => { + if (!specifierIsRelative(key)) { + warn(createExportsMappingKeyMustBeRelativeWarning({ + key, + keyPath: valuePath.slice(0, -1), + packageFileUrl + })); + return; + } - if (!specifierIsRelative(address)) { - logger.warn(` -found unexpected address in imports of package.json, it must be relative to package.json. ---- address --- -${address} ---- specifier --- -${specifier} ---- package.json path --- -${packageFilePath} -`); - return; - } + if (typeof value !== "string") { + warn(createExportsMappingValueMustBeAStringWarning({ + value, + valuePath, + packageFileUrl + })); + return; + } - let from; + if (!specifierIsRelative(value)) { + warn(createExportsMappingValueMustBeRelativeWarning({ + value, + valuePath, + packageFileUrl + })); + return; + } - if (specifier[0] === "/") { - from = specifier; - } else if (specifier.startsWith("./")) { - from = specifier; - } else { - from = specifier; + onExport({ + key: specifierToSource(key, packageName), + value: addressToDestination(value, packageDirectoryRelativeUrl) + }); } - - const to = address; - importsForPackageImports[from] = to; }); - return importsForPackageImports; }; -// https://nodejs.org/dist/latest-v13.x/docs/api/esm.html#esm_package_exports -const visitPackageExports = ({ - logger, - packageFileUrl, - packageName, - packageJsonObject, - packageInfo: { - packageDirectoryRelativeUrl - }, - packagesExportsPreference +const visitExportsSubpath = (packageExports, packageExportsConditions, { + onUnexpectedPackageExports, + onMixedPackageExports, + onSubpathPackageExport }) => { - const importsForPackageExports = {}; - const packageFilePath = util.urlToFileSystemPath(packageFileUrl); - const { - exports: packageExports - } = packageJsonObject; // false is allowed as laternative to exports: {} - - if (packageExports === false) { - return importsForPackageExports; - } - - const addRemapping = ({ - from, - to + const visitValue = (packageExportsValue, { + valuePath }) => { - if (from.indexOf("*") === -1) { - importsForPackageExports[from] = to; + // false is allowed as alternative to exports: {} + if (packageExportsValue === false) { return; } - if (from.endsWith("/*") && to.endsWith("/*") && // ensure ends with '*' AND there is only one '*' occurence - to.indexOf("*") === to.length - 1) { - const fromWithouTrailingStar = from.slice(0, -1); - const toWithoutTrailingStar = to.slice(0, -1); - importsForPackageExports[fromWithouTrailingStar] = toWithoutTrailingStar; + if (typeof packageExportsValue === "string") { + const firstNonConditionKey = valuePath.slice().reverse().find(key => key.startsWith(".")); + const key = firstNonConditionKey || "."; + onSubpathPackageExport({ + value: packageExportsValue, + valuePath, + key + }); return; } - logger.warn(`Ignoring export using "*" because it is not supported by importmap. ---- key --- -${from} ---- value --- -${to} ---- package.json path --- -${packageFilePath} ---- see also --- -https://github.com/WICG/import-maps/issues/232`); - }; // exports used to indicate the main file - - - if (typeof packageExports === "string") { - addRemapping({ - from: packageName, - to: addressToDestination(packageExports, packageDirectoryRelativeUrl) - }); - return importsForPackageExports; - } - - if (typeof packageExports !== "object" || packageExports === null) { - logger.warn(` -exports of package.json must be an object. ---- package.json exports --- -${packageExports} ---- package.json path --- -${packageFilePath} -`); - return importsForPackageExports; - } - - const packageExportsKeys = Object.keys(packageExports); - const someSpecifierStartsWithDot = packageExportsKeys.some(key => key.startsWith(".")); - - if (someSpecifierStartsWithDot) { - const someSpecifierDoesNotStartsWithDot = packageExportsKeys.some(key => !key.startsWith(".")); - - if (someSpecifierDoesNotStartsWithDot) { - // see https://nodejs.org/dist/latest-v13.x/docs/api/esm.html#esm_exports_sugar - logger.error(` -exports of package.json mixes conditional exports and direct exports. ---- package.json path --- -${packageFilePath} -`); - return importsForPackageExports; - } - } - - packageExportsKeys.forEach(specifier => { - if (!specifierIsRelative(specifier)) { - logger.warn(` -found unexpected specifier in exports of package.json, it must be relative to package.json. ---- specifier --- -${specifier} ---- package.json path --- -${packageFilePath} -`); + if (typeof packageExportsValue !== "object" && packageExportsValue !== null) { + onUnexpectedPackageExports({ + packageExportsValue, + packageExportsValuePath: valuePath + }); return; } - const value = packageExports[specifier]; - let address; + const keys = Object.keys(packageExportsValue); + const everyKeyDoesNotStartsWithDot = keys.every(key => !key.startsWith(".")); - if (typeof value === "object") { - address = readFavoredKey(value, packagesExportsPreference); + if (everyKeyDoesNotStartsWithDot) { + const bestConditionKey = findBestConditionKey(keys, packageExportsConditions); - if (!address) { + if (!bestConditionKey) { return; } - if (typeof address === "object") { - address = readFavoredKey(address, packagesExportsPreference); - - if (!address) { - return; - } - } - } else if (typeof value === "string") { - address = value; - } else { - logger.warn(` -found unexpected address in exports of package.json, it must be a string. ---- address --- -${address} ---- specifier --- -${specifier} ---- package.json path --- -${packageFilePath} -`); + const bestExports = packageExportsValue[bestConditionKey]; + visitValue(bestExports, { + valuePath: [...valuePath, bestConditionKey] + }); return; } - if (!specifierIsRelative(address)) { - logger.warn(` -found unexpected address in exports of package.json, it must be relative to package.json. ---- address --- -${address} ---- specifier --- -${specifier} ---- package.json path --- -${packageFilePath} -`); + const everyKeyStartsWithDot = keys.every(key => key.startsWith(".")); + + if (everyKeyStartsWithDot) { + keys.forEach(key => { + visitValue(packageExportsValue[key], { + valuePath: [...valuePath, key] + }); + }); return; } - addRemapping({ - from: specifierToSource(specifier, packageName), - to: addressToDestination(address, packageDirectoryRelativeUrl) + onMixedPackageExports({ + packageExportsValue, + packageExportsValuePath: valuePath }); + }; + + visitValue(packageExports, { + valuePath: ["exports"] }); - return importsForPackageExports; +}; + +const findBestConditionKey = (availableKeys, exportsConditions) => { + const conditionKey = exportsConditions.find(key => availableKeys.includes(key)); + + if (conditionKey) { + return conditionKey; + } + + if (availableKeys.includes("default")) { + return "default"; + } + + return undefined; }; const specifierToSource = (specifier, packageName) => { @@ -449,57 +1188,88 @@ const addressToDestination = (address, packageDirectoryRelativeUrl) => { return `./${packageDirectoryRelativeUrl}${address}`; }; -const readFavoredKey = (object, favoredKeys) => { - const favoredKey = favoredKeys.find(key => object.hasOwnProperty(key)); - - if (favoredKey) { - return object[favoredKey]; - } - - if (object.hasOwnProperty("default")) { - return object.default; - } - - return undefined; +const createExportsValueWarning = ({ + packageExportsValue, + packageExportsValuePath, + packageFileUrl +}) => { + return { + code: "EXPORTS_VALUE", + message: `unexpected value in package.json exports field: value must be an object or a string. +--- value --- +${packageExportsValue} +--- value path --- +${packageExportsValuePath.join(".")} +--- package.json path --- +${util.urlToFileSystemPath(packageFileUrl)}` + }; }; -const memoizeAsyncFunctionByUrl = fn => { - const cache = {}; - return async (url, ...args) => { - const promiseFromCache = cache[url]; - - if (promiseFromCache) { - return promiseFromCache; - } - - let _resolve; - - let _reject; - - const promise = new Promise((resolve, reject) => { - _resolve = resolve; - _reject = reject; - }); - cache[url] = promise; - let value; - let error; - - try { - value = fn(url, ...args); - error = false; - } catch (e) { - value = e; - error = true; - delete cache[url]; - } +const createExportsMixedWarning = ({ + packageExportsValue, + packageExportsValuePath, + packageFileUrl +}) => { + return { + code: "EXPORTS_MIXED", + message: `unexpected package.json exports field: cannot mix conditional and subpath exports. +--- value --- +${JSON.stringify(packageExportsValue, null, " ")} +--- value path --- +${packageExportsValuePath.join(".")} +--- package.json path --- +${util.urlToFileSystemPath(packageFileUrl)}` + }; +}; - if (error) { - _reject(error); - } else { - _resolve(value); - } +const createExportsMappingKeyMustBeRelativeWarning = ({ + key, + keyPath, + packageFileUrl +}) => { + return { + code: "EXPORTS_MAPPING_KEY_MUST_BE_RELATIVE", + message: `unexpected key in package.json exports field: key must be relative. +--- key --- +${key} +--- key path --- +${keyPath.join(".")} +--- package.json path --- +${util.urlToFileSystemPath(packageFileUrl)}` + }; +}; - return promise; +const createExportsMappingValueMustBeAStringWarning = ({ + value, + valuePath, + packageFileUrl +}) => { + return { + code: "EXPORTS_MAPPING_VALUE_MUST_BE_A_STRING", + message: `unexpected value in package.json exports field: value must be a string. +--- value --- +${value} +--- value path --- +${valuePath.join(".")} +--- package.json path --- +${util.urlToFileSystemPath(packageFileUrl)}` + }; +}; + +const createExportsMappingValueMustBeRelativeWarning = ({ + value, + valuePath, + packageFileUrl +}) => { + return { + code: "EXPORTS_MAPPING_VALUE_MUST_BE_RELATIVE", + message: `unexpected value in package.json exports field: value must be relative. +--- value --- +${value} +--- value path --- +${valuePath.join(".")} +--- package.json path --- +${util.urlToFileSystemPath(packageFileUrl)}` }; }; @@ -636,39 +1406,77 @@ const getNodeModuleCandidates = (fileUrl, projectDirectoryUrl) => { return [...candidates, "node_modules/"]; }; -const getImportMapFromNodeModules = async ({ +const getImportMapFromPackageFiles = async ({ // nothing is actually listening for this cancellationToken for now // it's not very important but it would be better to register on it // an stops what we are doing if asked to do so // cancellationToken = createCancellationTokenForProcess(), - logLevel, + logger, + warn, projectDirectoryUrl, - rootProjectDirectoryUrl, - importMapFileRelativeUrl = "./import-map.importmap", projectPackageDevDependenciesIncluded = "undefined" !== "production", packagesExportsPreference = ["import", "browser"], packagesExportsIncluded = true, - packagesSelfReference = true, - packagesImportsIncluded = true, packagesManualOverrides = {}, packageIncludedPredicate = () => true }) => { - const logger$1 = logger.createLogger({ - logLevel - }); projectDirectoryUrl = util.assertAndNormalizeDirectoryUrl(projectDirectoryUrl); - - if (typeof rootProjectDirectoryUrl === "undefined") { - rootProjectDirectoryUrl = projectDirectoryUrl; - } else { - rootProjectDirectoryUrl = util.assertAndNormalizeDirectoryUrl(rootProjectDirectoryUrl); - } - const projectPackageFileUrl = util.resolveUrl("./package.json", projectDirectoryUrl); - const rootProjectPackageFileUrl = util.resolveUrl("./package.json", rootProjectDirectoryUrl); const findNodeModulePackage = createFindNodeModulePackage(packagesManualOverrides); const imports = {}; const scopes = {}; + + const addTopLevelImportMapping = ({ + from, + to + }) => { + // we could think it's useless to remap from with to + // however it can be used to ensure a weaker remapping + // does not win over this specific file or folder + if (from === to) { + /** + * however remapping '/' to '/' is truly useless + * moreover it would make wrapImportMap create something like + * { + * imports: { + * "/": "/.dist/best/" + * } + * } + * that would append the wrapped folder twice + * */ + if (from === "/") return; + } + + imports[from] = to; + }; + + const addScopedImportMapping = ({ + scope, + from, + to + }) => { + // when a package says './' maps to './' + // we must add something to say if we are already inside the package + // no need to ensure leading slash are scoped to the package + if (from === "./" && to === scope) { + addScopedImportMapping({ + scope, + from: scope, + to: scope + }); + const packageName = scope.slice(scope.lastIndexOf("node_modules/") + `node_modules/`.length); + addScopedImportMapping({ + scope, + from: packageName, + to: scope + }); + } + + scopes[scope] = { ...(scopes[scope] || {}), + [from]: to + }; + }; + const seen = {}; const markPackageAsSeen = (packageFileUrl, importerPackageFileUrl) => { @@ -717,8 +1525,7 @@ const getImportMapFromNodeModules = async ({ packageFileUrl, packageName, packageJsonObject, - importerPackageFileUrl, - importerPackageJsonObject + importerPackageFileUrl }) => { const packageInfo = computePackageInfo({ packageFileUrl, @@ -731,151 +1538,164 @@ const getImportMapFromNodeModules = async ({ packageJsonObject, packageInfo }); + const { + importerIsRoot, + importerRelativeUrl, + packageIsRoot, + packageDirectoryRelativeUrl // packageDirectoryUrl, + // packageDirectoryUrlExpected, - if (packagesImportsIncluded && "imports" in packageJsonObject) { - const importsForPackageImports = visitPackageImports({ - logger: logger$1, - packageFileUrl, - packageName, - packageJsonObject, - packageInfo - }); - const { - packageIsRoot, - packageDirectoryRelativeUrl - } = packageInfo; - Object.keys(importsForPackageImports).forEach(from => { - const to = importsForPackageImports[from]; + } = packageInfo; - if (packageIsRoot) { + const addImportMapForPackage = importMap => { + if (packageIsRoot) { + const { + imports = {}, + scopes = {} + } = importMap; + Object.keys(imports).forEach(from => { addTopLevelImportMapping({ from, - to + to: imports[from] }); - } else { - const toScoped = to[0] === "/" ? to : `./${packageDirectoryRelativeUrl}${to.startsWith("./") ? to.slice(2) : to}`; - addScopedImportMapping({ - scope: `./${packageDirectoryRelativeUrl}`, - from, - to: toScoped - }); // when a package says './' maps to './' - // we must add something to say if we are already inside the package - // no need to ensure leading slash are scoped to the package - - if (from === "./" && to === "./") { - addScopedImportMapping({ - scope: `./${packageDirectoryRelativeUrl}`, - from: `./${packageDirectoryRelativeUrl}`, - to: `./${packageDirectoryRelativeUrl}` - }); - } else if (from === "/" && to === "/") { + }); + Object.keys(scopes).forEach(scope => { + const scopeMappings = scopes[scope]; + Object.keys(scopeMappings).forEach(key => { addScopedImportMapping({ - scope: `./${packageDirectoryRelativeUrl}`, - from: `./${packageDirectoryRelativeUrl}`, - to: `./${packageDirectoryRelativeUrl}` + scope, + from: key, + to: scopeMappings[key] }); - } - } - }); - } + }); + }); + return; + } - if (packagesSelfReference) { const { - packageIsRoot, - packageDirectoryRelativeUrl - } = packageInfo; // allow import 'package-name/dir/file.js' in package-name files - - if (packageIsRoot) { - addTopLevelImportMapping({ - from: `${packageName}/`, - to: `./${packageDirectoryRelativeUrl}` + imports = {}, + scopes = {} + } = importMap; + const scope = `./${packageDirectoryRelativeUrl}`; + Object.keys(imports).forEach(from => { + const to = imports[from]; + const toMoved = moveMappingValue(to, packageFileUrl, projectDirectoryUrl); + addScopedImportMapping({ + scope, + from, + to: toMoved }); - } // scoped allow import 'package-name/dir/file.js' in package-name files - else { + }); + Object.keys(scopes).forEach(scope => { + const scopeMappings = scopes[scope]; + const scopeMoved = moveMappingValue(scope, packageFileUrl, projectDirectoryUrl); + Object.keys(scopeMappings).forEach(key => { + const to = scopeMappings[key]; + const toMoved = moveMappingValue(to, packageFileUrl, projectDirectoryUrl); addScopedImportMapping({ - scope: `./${packageDirectoryRelativeUrl}`, - from: `${packageName}/`, - to: `./${packageDirectoryRelativeUrl}` + scope: scopeMoved, + from: key, + to: toMoved }); - } - } - - if (packagesExportsIncluded && "exports" in packageJsonObject) { - const importsForPackageExports = visitPackageExports({ - logger: logger$1, - packageFileUrl, - packageName, - packageJsonObject, - packageInfo, - packagesExportsPreference + }); }); - const { - importerIsRoot, - importerRelativeUrl, - packageIsRoot, - packageDirectoryRelativeUrl // packageDirectoryUrl, - // packageDirectoryUrlExpected, - - } = packageInfo; + }; - if (packageIsRoot && packagesSelfReference) { - Object.keys(importsForPackageExports).forEach(from => { - const to = importsForPackageExports[from]; + const addMappingsForPackageAndImporter = mappings => { + if (packageIsRoot) { + Object.keys(mappings).forEach(from => { + const to = mappings[from]; addTopLevelImportMapping({ from, to }); }); - } else if (packageIsRoot) ; else { - Object.keys(importsForPackageExports).forEach(from => { - const to = importsForPackageExports[from]; // own package exports available to himself - - if (importerIsRoot) { - // importer is the package himself, keep exports scoped - // otherwise the dependency exports would override the package exports. - if (importerPackageJsonObject.name === packageName) { - addScopedImportMapping({ - scope: `./${packageDirectoryRelativeUrl}`, - from, - to - }); - - if (from === packageName || from in imports === false) { - addTopLevelImportMapping({ - from, - to - }); - } - } else { - addTopLevelImportMapping({ - from, - to - }); - } - } else { - addScopedImportMapping({ - scope: `./${packageDirectoryRelativeUrl}`, - from, - to - }); - } // now make package exports available to the importer - // if importer is root no need because the top level remapping does it - - - if (importerIsRoot) { - return; - } // now make it available to the importer - // here if the importer is himself we could do stuff - // we should even handle the case earlier to prevent top level remapping - + return; + } + if (importerIsRoot) { + // own package mappings available to himself + Object.keys(mappings).forEach(from => { + const to = mappings[from]; addScopedImportMapping({ - scope: `./${importerRelativeUrl}`, + scope: `./${packageDirectoryRelativeUrl}`, from, to }); - }); + addTopLevelImportMapping({ + from, + to + }); + }); // if importer is root no need to make package mappings available to the importer + // because they are already on top level mappings + + return; } + + Object.keys(mappings).forEach(from => { + const to = mappings[from]; // own package exports available to himself + + addScopedImportMapping({ + scope: `./${packageDirectoryRelativeUrl}`, + from, + to + }); // now make package exports available to the importer + // here if the importer is himself we could do stuff + // we should even handle the case earlier to prevent top level remapping + + addScopedImportMapping({ + scope: `./${importerRelativeUrl}`, + from, + to + }); + }); + }; + + const importsFromPackageField = await visitPackageImportMap({ + warn, + packageFileUrl, + packageJsonObject, + projectDirectoryUrl + }); + addImportMapForPackage(importsFromPackageField); + + if (packagesExportsIncluded && "exports" in packageJsonObject) { + const mappingsFromPackageExports = {}; + visitPackageExports({ + warn, + packageFileUrl, + packageJsonObject, + packageName, + projectDirectoryUrl, + packagesExportsPreference, + onExport: ({ + key, + value + }) => { + const from = key; + const to = value; + + if (from.indexOf("*") === -1) { + mappingsFromPackageExports[from] = to; + return; + } + + if (from.endsWith("/*") && to.endsWith("/*") && // ensure ends with '*' AND there is only one '*' occurence + to.indexOf("*") === to.length - 1) { + const fromWithouTrailingStar = from.slice(0, -1); + const toWithoutTrailingStar = to.slice(0, -1); + mappingsFromPackageExports[fromWithouTrailingStar] = toWithoutTrailingStar; + return; + } + + warn(createExportsWildcardIgnoredWarning({ + key, + value, + packageFileUrl + })); + } + }); + addMappingsForPackageAndImporter(mappingsFromPackageExports); } }; @@ -886,24 +1706,24 @@ const getImportMapFromNodeModules = async ({ packageInfo: { importerIsRoot, importerRelativeUrl, - packageIsRoot, - packageIsProject, packageDirectoryUrl, packageDirectoryUrlExpected } }) => { - const self = packageIsRoot || packageIsProject; - if (self && !packagesSelfReference) return; const mainFileUrl = await resolvePackageMain({ + warn, + packagesExportsPreference, packageFileUrl, - packageJsonObject, - logger: logger$1 + packageJsonObject }); // it's possible to have no main // like { main: "" } in package.json // or a main that does not lead to an actual file - if (mainFileUrl === null) return; - const mainFileRelativeUrl = util.urlToRelativeUrl(mainFileUrl, rootProjectDirectoryUrl); + if (mainFileUrl === null) { + return; + } + + const mainFileRelativeUrl = util.urlToRelativeUrl(mainFileUrl, projectDirectoryUrl); const from = packageName; const to = `./${mainFileRelativeUrl}`; @@ -960,11 +1780,18 @@ const getImportMapFromNodeModules = async ({ }); if (!dependencyData) { - logger$1[dependencyInfo.isOptional ? "debug" : "warn"](formatCannotFindPackageLog({ + const cannotFindPackageWarning = createCannotFindPackageWarning({ dependencyName, dependencyInfo, packageFileUrl - })); + }); + + if (dependencyInfo.isOptional) { + logger.debug(cannotFindPackageWarning.message); + } else { + warn(cannotFindPackageWarning); + } + return; } @@ -992,68 +1819,23 @@ const getImportMapFromNodeModules = async ({ packageName, importerPackageFileUrl }) => { - const importerIsRoot = importerPackageFileUrl === rootProjectPackageFileUrl; - const importerIsProject = importerPackageFileUrl === projectPackageFileUrl; + const importerIsRoot = importerPackageFileUrl === projectPackageFileUrl; const importerPackageDirectoryUrl = util.resolveUrl("./", importerPackageFileUrl); - const importerRelativeUrl = importerIsRoot ? `${util.urlToBasename(rootProjectDirectoryUrl.slice(0, -1))}/` : util.urlToRelativeUrl(importerPackageDirectoryUrl, rootProjectDirectoryUrl); - const packageIsRoot = packageFileUrl === rootProjectPackageFileUrl; - const packageIsProject = packageFileUrl === projectPackageFileUrl; + const importerRelativeUrl = importerIsRoot ? `${util.urlToBasename(projectDirectoryUrl.slice(0, -1))}/` : util.urlToRelativeUrl(importerPackageDirectoryUrl, projectDirectoryUrl); + const packageIsRoot = packageFileUrl === projectPackageFileUrl; const packageDirectoryUrl = util.resolveUrl("./", packageFileUrl); - let packageDirectoryUrlExpected; - - if (packageIsProject && !packageIsRoot) { - packageDirectoryUrlExpected = importerPackageDirectoryUrl; - } else { - packageDirectoryUrlExpected = `${importerPackageDirectoryUrl}node_modules/${packageName}/`; - } - - const packageDirectoryRelativeUrl = util.urlToRelativeUrl(packageDirectoryUrl, rootProjectDirectoryUrl); + const packageDirectoryUrlExpected = `${importerPackageDirectoryUrl}node_modules/${packageName}/`; + const packageDirectoryRelativeUrl = util.urlToRelativeUrl(packageDirectoryUrl, projectDirectoryUrl); return { importerIsRoot, - importerIsProject, importerRelativeUrl, packageIsRoot, - packageIsProject, packageDirectoryUrl, packageDirectoryUrlExpected, packageDirectoryRelativeUrl }; }; - const addTopLevelImportMapping = ({ - from, - to - }) => { - // we could think it's useless to remap from with to - // however it can be used to ensure a weaker remapping - // does not win over this specific file or folder - if (from === to) { - /** - * however remapping '/' to '/' is truly useless - * moreover it would make wrapImportMap create something like - * { - * imports: { - * "/": "/.dist/best/" - * } - * } - * that would append the wrapped folder twice - * */ - if (from === "/") return; - } - - imports[from] = to; - }; - - const addScopedImportMapping = ({ - scope, - from, - to - }) => { - scopes[scope] = { ...(scopes[scope] || {}), - [from]: to - }; - }; - const dependenciesCache = {}; const findDependency = ({ @@ -1069,7 +1851,7 @@ const getImportMapFromNodeModules = async ({ } const dependencyPromise = findNodeModulePackage({ - projectDirectoryUrl: rootProjectDirectoryUrl, + projectDirectoryUrl, packageFileUrl, dependencyName }); @@ -1085,7 +1867,7 @@ const getImportMapFromNodeModules = async ({ const packageName = projectPackageJsonObject.name; if (typeof packageName !== "string") { - logger$1.warn(formatUnexpectedPackageNameLog({ + warn(createPackageNameMustBeAStringWarning({ packageName, packageFileUrl: projectPackageFileUrl })); @@ -1099,40 +1881,11 @@ const getImportMapFromNodeModules = async ({ importerPackageFileUrl, importerPackageJsonObject: null, includeDevDependencies: projectPackageDevDependenciesIncluded - }); // remove useless duplicates (scoped key+value already defined on imports) - - Object.keys(scopes).forEach(key => { - const scopedImports = scopes[key]; - Object.keys(scopedImports).forEach(scopedImportKey => { - if (scopedImportKey in imports && imports[scopedImportKey] === scopedImports[scopedImportKey]) { - delete scopedImports[scopedImportKey]; - } - }); - - if (Object.keys(scopedImports).length === 0) { - delete scopes[key]; - } - }); // The importmap generated at this point is relative to the project directory url - // In other words if you want to use that importmap you have to put it - // inside projectDirectoryUrl (it cannot be nested in a subdirectory). - - let importMap$1 = { + }); + return optimizeImportMap({ imports, scopes - }; - - if (importMapFileRelativeUrl) { - // When there is an importMapFileRelativeUrl we will make remapping relative - // to the importmap file future location (where user will write it). - // This allows to put the importmap anywhere inside the projectDirectoryUrl. - // (If possible prefer to have it top level to avoid too many ../ - const importMapProjectUrl = util.resolveUrl("project.importmap", projectDirectoryUrl); - const importMapRealUrl = util.resolveUrl(importMapFileRelativeUrl, projectDirectoryUrl); - importMap$1 = importMap.moveImportMap(importMap$1, importMapProjectUrl, importMapRealUrl); - } - - importMap$1 = importMap.sortImportMap(importMap$1); - return importMap$1; + }); }; const packageDependenciesFromPackageObject = (packageObject, { @@ -1184,20 +1937,60 @@ const packageDependenciesFromPackageObject = (packageObject, { return packageDependencies; }; -const formatUnexpectedPackageNameLog = ({ +const moveMappingValue = (address, from, to) => { + const url = util.resolveUrl(address, from); + const relativeUrl = util.urlToRelativeUrl(url, to); + + if (relativeUrl.startsWith("../")) { + return relativeUrl; + } + + if (relativeUrl.startsWith("./")) { + return relativeUrl; + } + + if (/^[a-zA-Z]{2,}:/.test(relativeUrl)) { + // has sheme + return relativeUrl; + } + + return `./${relativeUrl}`; +}; + +const createExportsWildcardIgnoredWarning = ({ + key, + value, + packageFileUrl +}) => { + return { + code: "EXPORTS_WILDCARD", + message: `Ignoring export using "*" because it is not supported by importmap. +--- key --- +${key} +--- value --- +${value} +--- package.json path --- +${util.urlToFileSystemPath(packageFileUrl)} +--- see also --- +https://github.com/WICG/import-maps/issues/232` + }; +}; + +const createPackageNameMustBeAStringWarning = ({ packageName, packageFileUrl }) => { - return ` -package name field must be a string + return { + code: "PACKAGE_NAME_MUST_BE_A_STRING", + message: `package name field must be a string --- package name field --- ${packageName} --- package.json file path --- -${packageFileUrl} -`; +${packageFileUrl}` + }; }; -const formatCannotFindPackageLog = ({ +const createCannotFindPackageWarning = ({ dependencyName, dependencyInfo, packageFileUrl @@ -1205,20 +1998,87 @@ const formatCannotFindPackageLog = ({ const dependencyIsOptional = dependencyInfo.isOptional; const dependencyType = dependencyInfo.type; const dependencyVersionPattern = dependencyInfo.versionPattern; - const detailedMessage = logger.createDetailedMessage(dependencyIsOptional ? `cannot find an optional ${dependencyType}.` : `cannot find a ${dependencyType}.`, { - [dependencyType]: `${dependencyName}@${dependencyVersionPattern}`, - "required by": util.urlToFileSystemPath(packageFileUrl) + return { + code: "CANNOT_FIND_PACKAGE", + message: logger.createDetailedMessage(dependencyIsOptional ? `cannot find an optional ${dependencyType}.` : `cannot find a ${dependencyType}.`, { + [dependencyType]: `${dependencyName}@${dependencyVersionPattern}`, + "required by": util.urlToFileSystemPath(packageFileUrl) + }) + }; +}; + +const getImportMapFromProjectFiles = async ({ + logLevel, + projectDirectoryUrl, + runtime = "browser", + moduleFormat = "esm", + dev = false, + jsFiles = false, + removeUnusedMappings = !dev, + magicExtensions, + onWarn = (warning, warn) => { + warn(warning); + }, + ...rest +}) => { + const packagesExportsPreference = [...(moduleFormatPreferences[moduleFormat] || [moduleFormat]), ...(runtimeExportsPreferences[runtime] || [runtime]), ...(dev ? "development" : "production")]; + const logger$1 = logger.createLogger({ + logLevel }); - return ` -${detailedMessage} -`; + + const warn = warning => { + onWarn(warning, () => { + logger$1.warn(`\n${warning.message}\n`); + }); + }; // At this point, importmap is relative to the project directory url + + + let importMapFromPackageFiles = await getImportMapFromPackageFiles({ + logger: logger$1, + warn, + projectDirectoryUrl, + packagesExportsPreference, + projectPackageDevDependenciesIncluded: dev, + ...rest + }); + importMapFromPackageFiles = importMap.sortImportMap(importMapFromPackageFiles); + let importMapFromJsFiles = jsFiles ? await getImportMapFromJsFiles({ + logLevel, + warn, + importMap: importMapFromPackageFiles, + removeUnusedMappings, + projectDirectoryUrl, + magicExtensions, + packagesExportsPreference, + runtime + }) : {}; + importMapFromJsFiles = importMap.sortImportMap(importMapFromJsFiles); + return importMap.sortImportMap(importMap.composeTwoImportMaps(importMapFromPackageFiles, importMapFromJsFiles)); +}; +const runtimeExportsPreferences = { + browser: ["browser"], + node: ["node"] }; +const moduleFormatPreferences = { + esm: ["import"], + cjs: ["require"] +}; + +const getImportMapFromFile = async ({ + projectDirectoryUrl, + importMapFileRelativeUrl +}) => { + projectDirectoryUrl = util.assertAndNormalizeDirectoryUrl(projectDirectoryUrl); + const importmapFileUrl = util.resolveUrl(importMapFileRelativeUrl, projectDirectoryUrl); + const importmap = await util.readFile(importmapFileUrl, { + as: "json" + }); // ensure the importmap is now relative to the project directory url + // we do that because writeImportMapFile expect all importmap + // to be relative to the projectDirectoryUrl -const getImportMapFromFile = async importMapFilePath => { - const importMapFileUrl = util.assertAndNormalizeFileUrl(importMapFilePath); - const importMapFileContent = await util.readFile(importMapFileUrl); - const importMap = JSON.parse(importMapFileContent); - return importMap; + const importmapFakeRootUrl = util.resolveUrl("whatever.importmap", projectDirectoryUrl); + const importmapRelativeToProject = importMap.moveImportMap(importmap, importmapFileUrl, importmapFakeRootUrl); + return importMap.sortImportMap(importmapRelativeToProject); }; const importMapToVsCodeConfigPaths = ({ @@ -1253,7 +2113,7 @@ const importMapToVsCodeConfigPaths = ({ return paths; }; -const generateImportMapForProject = async (importMapInputs = [], { +const writeImportMapFile = async (importMapInputs = [], { projectDirectoryUrl, importMapFile = true, // in case someone wants the importmap but not write it on filesystem @@ -1315,8 +2175,8 @@ const generateImportMapForProject = async (importMapInputs = [], { return importMap$1; }; -exports.generateImportMapForProject = generateImportMapForProject; exports.getImportMapFromFile = getImportMapFromFile; -exports.getImportMapFromNodeModules = getImportMapFromNodeModules; +exports.getImportMapFromProjectFiles = getImportMapFromProjectFiles; +exports.writeImportMapFile = writeImportMapFile; //# sourceMappingURL=main.cjs.map \ No newline at end of file diff --git a/dist/commonjs/main.cjs.map b/dist/commonjs/main.cjs.map index e5c7642c..114b6217 100644 --- a/dist/commonjs/main.cjs.map +++ b/dist/commonjs/main.cjs.map @@ -2,38 +2,180 @@ "version": 3, "file": "main.cjs", "sources": [ + "../../src/internal/memoizeAsyncFunction.js", + "../../node_modules/@jsenv/core/helpers/import-meta/import-meta-url-commonjs.js", + "../../src/internal/from-js/parseSpecifiersFromFile.js", + "../../src/internal/from-js/showSource.js", "../../src/internal/resolveFile.js", - "../../src/internal/resolvePackageMain.js", - "../../src/internal/specifierIsRelative.js", - "../../src/internal/visitPackageImports.js", - "../../src/internal/visitPackageExports.js", - "../../src/internal/memoizeAsyncFunctionByUrl.js", - "../../src/internal/applyPackageManualOverride.js", - "../../src/internal/readPackageFile.js", - "../../src/internal/node-module-resolution.js", - "../../src/getImportMapFromNodeModules.js", + "../../src/internal/from-js/getImportMapFromJsFiles.js", + "../../src/internal/optimizeImportMap.js", + "../../src/internal/from-package/resolvePackageMain.js", + "../../src/internal/from-package/visitPackageImportMap.js", + "../../src/internal/from-package/specifierIsRelative.js", + "../../src/internal/from-package/visitPackageExports.js", + "../../src/internal/from-package/applyPackageManualOverride.js", + "../../src/internal/from-package/readPackageFile.js", + "../../src/internal/from-package/node-module-resolution.js", + "../../src/internal/from-package/getImportMapFromPackageFiles.js", + "../../src/getImportMapFromProjectFiles.js", "../../src/getImportMapFromFile.js", "../../src/internal/importMapToVsCodeConfigPaths.js", - "../../src/generateImportMapForProject.js" + "../../src/writeImportMapFile.js" ], "sourcesContent": [ - "import { resolveUrl, readFileSystemNodeStat, urlToBasename, urlToExtension } from \"@jsenv/util\"\nimport { firstOperationMatching } from \"@jsenv/cancellation\"\n\nexport const resolveFile = async (fileUrl, { magicExtensions }) => {\n const fileStat = await readFileSystemNodeStat(fileUrl, {\n nullIfNotFound: true,\n })\n\n // file found\n if (fileStat && fileStat.isFile()) {\n return fileUrl\n }\n\n // directory found\n if (fileStat && fileStat.isDirectory()) {\n const indexFileSuffix = fileUrl.endsWith(\"/\") ? \"index\" : \"/index\"\n const indexFileUrl = `${fileUrl}${indexFileSuffix}`\n const extensionLeadingToAFile = await findExtensionLeadingToFile(indexFileUrl, magicExtensions)\n if (extensionLeadingToAFile === null) {\n return null\n }\n return `${indexFileUrl}.${extensionLeadingToAFile}`\n }\n\n // file not found and it has an extension\n const extension = urlToExtension(fileUrl)\n if (extension !== \"\") {\n return null\n }\n\n const extensionLeadingToAFile = await findExtensionLeadingToFile(fileUrl, magicExtensions)\n // magic extension not found\n if (extensionLeadingToAFile === null) {\n return null\n }\n\n // magic extension worked\n return `${fileUrl}.${extensionLeadingToAFile}`\n}\n\nconst findExtensionLeadingToFile = async (fileUrl, magicExtensions) => {\n const fileDirectoryUrl = resolveUrl(\"./\", fileUrl)\n const fileBasename = urlToBasename(fileUrl)\n const extensionLeadingToFile = await firstOperationMatching({\n array: magicExtensions,\n start: async (extensionCandidate) => {\n const filePathCandidate = `${fileDirectoryUrl}/${fileBasename}.${extensionCandidate}`\n const stats = await readFileSystemNodeStat(filePathCandidate, { nullIfNotFound: true })\n return stats && stats.isFile() ? extensionCandidate : null\n },\n predicate: (extension) => Boolean(extension),\n })\n return extensionLeadingToFile || null\n}\n", - "import { createDetailedMessage } from \"@jsenv/logger\"\nimport { resolveUrl, urlToFileSystemPath, urlToExtension } from \"@jsenv/util\"\nimport { resolveFile } from \"./resolveFile.js\"\n\nconst magicExtensions = [\"js\", \"json\", \"node\"]\n\nexport const resolvePackageMain = ({ logger, packageFileUrl, packageJsonObject }) => {\n if (\"module\" in packageJsonObject) {\n return resolveMainFile({\n logger,\n packageFileUrl,\n packageMainFieldName: \"module\",\n packageMainFieldValue: packageJsonObject.module,\n })\n }\n\n if (\"jsnext:main\" in packageJsonObject) {\n return resolveMainFile({\n logger,\n packageFileUrl,\n packageMainFieldName: \"jsnext:main\",\n packageMainFieldValue: packageJsonObject[\"jsnext:main\"],\n })\n }\n\n if (\"main\" in packageJsonObject) {\n return resolveMainFile({\n logger,\n packageFileUrl,\n packageMainFieldName: \"main\",\n packageMainFieldValue: packageJsonObject.main,\n })\n }\n\n return resolveMainFile({\n logger,\n packageFileUrl,\n packageMainFieldName: \"default\",\n packageMainFieldValue: \"index\",\n })\n}\n\nconst resolveMainFile = async ({\n logger,\n packageFileUrl,\n packageMainFieldName,\n packageMainFieldValue,\n}) => {\n // main is explicitely empty meaning\n // it is assumed that we should not find a file\n if (packageMainFieldValue === \"\") {\n return null\n }\n\n const packageFilePath = urlToFileSystemPath(packageFileUrl)\n const packageDirectoryUrl = resolveUrl(\"./\", packageFileUrl)\n const mainFileRelativeUrl = packageMainFieldValue.endsWith(\"/\")\n ? `${packageMainFieldValue}index`\n : packageMainFieldValue\n\n const mainFileUrlFirstCandidate = resolveUrl(mainFileRelativeUrl, packageFileUrl)\n\n if (!mainFileUrlFirstCandidate.startsWith(packageDirectoryUrl)) {\n logger.warn(\n `\n${packageMainFieldName} field in package.json must be inside package.json folder.\n--- ${packageMainFieldName} ---\n${packageMainFieldValue}\n--- package.json path ---\n${packageFilePath}\n`,\n )\n return null\n }\n\n const mainFileUrl = await resolveFile(mainFileUrlFirstCandidate, {\n magicExtensions,\n })\n\n if (!mainFileUrl) {\n // we know in advance this remapping does not lead to an actual file.\n // we only warn because we have no guarantee this remapping will actually be used\n // in the codebase.\n // warn only if there is actually a main field\n // otherwise the package.json is missing the main field\n // it certainly means it's not important\n if (packageMainFieldName !== \"default\") {\n logger.warn(\n formatFileNotFoundLog({\n specifier: packageMainFieldValue,\n importedIn: `${packageFileUrl}#${packageMainFieldName}`,\n fileUrl: mainFileUrlFirstCandidate,\n magicExtensions,\n }),\n )\n }\n return mainFileUrlFirstCandidate\n }\n\n return mainFileUrl\n}\n\nconst formatFileNotFoundLog = ({ specifier, importedIn, fileUrl, magicExtensions }) => {\n return createDetailedMessage(`Cannot find file for \"${specifier}\"`, {\n \"imported in\": importedIn,\n \"file url\": fileUrl,\n ...(urlToExtension(fileUrl) === \"\" ? { [\"extensions tried\"]: magicExtensions.join(`,`) } : {}),\n })\n}\n", + "export const memoizeAsyncFunctionByUrl = (fn) => {\n const cache = {}\n return memoizeAsyncFunction(fn, {\n getMemoryEntryFromArguments: ([url]) => {\n return {\n get: () => {\n return cache[url]\n },\n set: (promise) => {\n cache[url] = promise\n },\n delete: () => {\n delete cache[url]\n },\n }\n },\n })\n}\n\nexport const memoizeAsyncFunctionBySpecifierAndImporter = (fn) => {\n const importerCache = {}\n return memoizeAsyncFunction(fn, {\n getMemoryEntryFromArguments: ([specifier, importer]) => {\n return {\n get: () => {\n const specifierCacheForImporter = importerCache[importer]\n return specifierCacheForImporter ? specifierCacheForImporter[specifier] : null\n },\n set: (promise) => {\n const specifierCacheForImporter = importerCache[importer]\n if (specifierCacheForImporter) {\n specifierCacheForImporter[specifier] = promise\n } else {\n importerCache[importer] = {\n [specifier]: promise,\n }\n }\n },\n delete: () => {\n const specifierCacheForImporter = importerCache[importer]\n if (specifierCacheForImporter) {\n delete specifierCacheForImporter[specifier]\n }\n },\n }\n },\n })\n}\n\nconst memoizeAsyncFunction = (fn, { getMemoryEntryFromArguments }) => {\n return async (...args) => {\n const memoryEntry = getMemoryEntryFromArguments(args)\n const promiseFromMemory = memoryEntry.get()\n if (promiseFromMemory) {\n return promiseFromMemory\n }\n let _resolve\n let _reject\n const promise = new Promise((resolve, reject) => {\n _resolve = resolve\n _reject = reject\n })\n memoryEntry.set(promise)\n let value\n let error\n try {\n value = fn(...args)\n error = false\n } catch (e) {\n value = e\n error = true\n memoryEntry.delete()\n }\n if (error) {\n _reject(error)\n } else {\n _resolve(value)\n }\n return promise\n }\n}\n", + "/* global __filename */\n\nconst filenameContainsBackSlashes = __filename.indexOf(\"\\\\\") > -1\n\nconst url = filenameContainsBackSlashes\n ? `file:///${__filename.replace(/\\\\/g, \"/\")}`\n : `file://${__filename}`\n\nexport default url\n", + "import { createRequire } from \"module\"\nimport { readFile, urlToFileSystemPath } from \"@jsenv/util\"\n\nconst require = createRequire(import.meta.url)\n\nconst parser = require(\"@babel/parser\")\nconst traverse = require(\"@babel/traverse\")\n\nexport const parseSpecifiersFromFile = async (\n fileUrl,\n {\n fileContent,\n sourceType = \"module\",\n allowImportExportEverywhere = true,\n allowAwaitOutsideFunction = true,\n ranges = true,\n jsx = true,\n typescript = true,\n flow = false,\n ...options\n } = {},\n) => {\n fileContent = fileContent === undefined ? await readFile(fileUrl, { as: \"string\" }) : fileContent\n\n const ast = parser.parse(fileContent, {\n sourceType,\n sourceFilename: urlToFileSystemPath(fileUrl),\n allowImportExportEverywhere,\n allowAwaitOutsideFunction,\n ranges,\n plugins: [\n // \"estree\",\n \"topLevelAwait\",\n \"exportDefaultFrom\",\n ...(jsx ? [\"jsx\"] : []),\n ...(typescript ? [\"typescript\"] : []),\n ...(flow ? [\"jsx\"] : []),\n ],\n ...options,\n })\n\n const specifiers = {}\n\n const addSpecifier = ({ path, type }) => {\n const specifier = path.node.value\n specifiers[specifier] = {\n line: path.node.loc.start.line,\n column: path.node.loc.start.column,\n type,\n }\n }\n\n traverse.default(ast, {\n // ImportExpression: (path) => {\n // if (path.node.arguments[0].type !== \"StringLiteral\") {\n // // Non-string argument, probably a variable or expression, e.g.\n // // import(moduleId)\n // // import('./' + moduleName)\n // return\n // }\n // addSpecifier(path.get(\"arguments\")[0])\n // },\n CallExpression: (path) => {\n if (path.node.callee.type !== \"Import\") {\n // Some other function call, not import();\n return\n }\n if (path.node.arguments[0].type !== \"StringLiteral\") {\n // Non-string argument, probably a variable or expression, e.g.\n // import(moduleId)\n // import('./' + moduleName)\n return\n }\n addSpecifier({\n path: path.get(\"arguments\")[0],\n type: \"import-dynamic\",\n })\n },\n ExportAllDeclaration: (path) => {\n addSpecifier({\n path: path.get(\"source\"),\n type: \"export-all\",\n })\n },\n ExportNamedDeclaration: (path) => {\n if (!path.node.source) {\n // This export has no \"source\", so it's probably\n // a local variable or function, e.g.\n // export { varName }\n // export const constName = ...\n // export function funcName() {}\n return\n }\n addSpecifier({\n path: path.get(\"source\"),\n type: \"export-named\",\n })\n },\n ImportDeclaration: (path) => {\n addSpecifier({\n path: path.get(\"source\"),\n type: \"import-static\",\n })\n },\n })\n\n return specifiers\n}\n", + "// https://github.com/postcss/postcss/blob/fd30d3df5abc0954a0ec642a3cdc644ab2aacf9c/lib/css-syntax-error.js#L43\n// https://github.com/postcss/postcss/blob/fd30d3df5abc0954a0ec642a3cdc644ab2aacf9c/lib/terminal-highlight.js#L50\n// https://github.com/babel/babel/blob/eea156b2cb8deecfcf82d52aa1b71ba4995c7d68/packages/babel-code-frame/src/index.js#L1\n\nexport const showSource = ({ url, line, column, source }) => {\n let message = \"\"\n\n message += typeof url === \"undefined\" ? \"Anonymous\" : url\n if (typeof line !== \"number\") {\n return message\n }\n\n message += `:${line}`\n if (typeof column === \"number\") {\n message += `:${column}`\n }\n\n if (!source) {\n return message\n }\n\n return `${message}\n${showSourceLocation(source, {\n line,\n column,\n})}`\n}\n\nconst red = \"\\x1b[31m\"\nconst grey = \"\\x1b[39m\"\nconst ansiResetSequence = \"\\x1b[0m\"\n\nconst showSourceLocation = (\n source,\n {\n line,\n column,\n numberOfSurroundingLinesToShow = 1,\n lineMaxLength = 120,\n color = false,\n markColor = red,\n asideColor = grey,\n colorMark = (string) => `${markColor}${string}${ansiResetSequence}`,\n colorAside = (string) => `${asideColor}${string}${ansiResetSequence}`,\n },\n) => {\n const mark = color ? colorMark : (string) => string\n const aside = color ? colorAside : (string) => string\n\n const lines = source.split(/\\r?\\n/)\n let lineRange = {\n start: line - 1,\n end: line,\n }\n lineRange = moveLineRangeUp(lineRange, numberOfSurroundingLinesToShow)\n lineRange = moveLineRangeDown(lineRange, numberOfSurroundingLinesToShow)\n lineRange = lineRangeWithinLines(lineRange, lines)\n const linesToShow = lines.slice(lineRange.start, lineRange.end)\n const endLineNumber = lineRange.end\n const lineNumberMaxWidth = String(endLineNumber).length\n\n const columnRange = {}\n if (column === undefined) {\n columnRange.start = 0\n columnRange.end = lineMaxLength\n } else if (column > lineMaxLength) {\n columnRange.start = column - Math.floor(lineMaxLength / 2)\n columnRange.end = column + Math.ceil(lineMaxLength / 2)\n } else {\n columnRange.start = 0\n columnRange.end = lineMaxLength\n }\n\n return linesToShow.map((lineSource, index) => {\n const lineNumber = lineRange.start + index + 1\n const isMainLine = lineNumber === line\n const lineSourceTruncated = applyColumnRange(columnRange, lineSource)\n const lineNumberWidth = String(lineNumber).length\n // ensure if line moves from 7,8,9 to 10 the display is still great\n const lineNumberRightSpacing = \" \".repeat(lineNumberMaxWidth - lineNumberWidth)\n const asideSource = `${lineNumber}${lineNumberRightSpacing} |`\n const lineFormatted = `${aside(asideSource)} ${lineSourceTruncated}`\n if (isMainLine) {\n if (column === undefined) {\n return `${mark(\">\")} ${lineFormatted}`\n }\n const lineSourceUntilColumn = lineSourceTruncated.slice(0, column - columnRange.start)\n const spacing = stringToSpaces(lineSourceUntilColumn)\n const mainLineFormatted = `${mark(\">\")} ${lineFormatted}\n ${\" \".repeat(lineNumberWidth)} ${aside(\"|\")}${spacing}${mark(\"^\")}`\n return mainLineFormatted\n }\n return ` ${lineFormatted}`\n }).join(`\n`)\n}\n\nconst applyColumnRange = ({ start, end }, line) => {\n if (typeof start !== \"number\") {\n throw new TypeError(`start must be a number, received ${start}`)\n }\n if (typeof end !== \"number\") {\n throw new TypeError(`end must be a number, received ${end}`)\n }\n if (end < start) {\n throw new Error(`end must be greater than start, but ${end} is smaller than ${start}`)\n }\n\n const prefix = \"…\"\n const suffix = \"…\"\n const lastIndex = line.length\n\n if (line.length === 0) {\n // don't show any ellipsis if the line is empty\n // because it's not truncated in that case\n return \"\"\n }\n\n const startTruncated = start > 0\n const endTruncated = lastIndex > end\n\n let from = startTruncated ? start + prefix.length : start\n let to = endTruncated ? end - suffix.length : end\n if (to > lastIndex) to = lastIndex\n\n if (start >= lastIndex || from === to) {\n return \"\"\n }\n\n let result = \"\"\n while (from < to) {\n result += line[from]\n from++\n }\n\n if (result.length === 0) {\n return \"\"\n }\n if (startTruncated && endTruncated) {\n return `${prefix}${result}${suffix}`\n }\n if (startTruncated) {\n return `${prefix}${result}`\n }\n if (endTruncated) {\n return `${result}${suffix}`\n }\n return result\n}\n\nconst stringToSpaces = (string) => string.replace(/[^\\t]/g, \" \")\n\n// const getLineRangeLength = ({ start, end }) => end - start\n\nconst moveLineRangeUp = ({ start, end }, number) => {\n return {\n start: start - number,\n end,\n }\n}\n\nconst moveLineRangeDown = ({ start, end }, number) => {\n return {\n start,\n end: end + number,\n }\n}\n\nconst lineRangeWithinLines = ({ start, end }, lines) => {\n return {\n start: start < 0 ? 0 : start,\n end: end > lines.length ? lines.length : end,\n }\n}\n", + "import { resolveUrl, readFileSystemNodeStat, urlToFilename, urlToExtension } from \"@jsenv/util\"\nimport { firstOperationMatching } from \"@jsenv/cancellation\"\n\nexport const resolveFile = async (fileUrl, { magicExtensions }) => {\n const fileStat = await readFileSystemNodeStat(fileUrl, {\n nullIfNotFound: true,\n })\n\n // file found\n if (fileStat && fileStat.isFile()) {\n return fileUrl\n }\n\n // directory found\n if (fileStat && fileStat.isDirectory()) {\n const indexFileSuffix = fileUrl.endsWith(\"/\") ? \"index\" : \"/index\"\n const indexFileUrl = `${fileUrl}${indexFileSuffix}`\n const extensionLeadingToAFile = await findExtensionLeadingToFile(indexFileUrl, magicExtensions)\n if (extensionLeadingToAFile === null) {\n return null\n }\n return `${indexFileUrl}${extensionLeadingToAFile}`\n }\n\n // file not found and it has an extension\n const extension = urlToExtension(fileUrl)\n if (extension !== \"\") {\n return null\n }\n\n const extensionLeadingToAFile = await findExtensionLeadingToFile(fileUrl, magicExtensions)\n // magic extension not found\n if (extensionLeadingToAFile === null) {\n return null\n }\n\n // magic extension worked\n return `${fileUrl}${extensionLeadingToAFile}`\n}\n\nconst findExtensionLeadingToFile = async (fileUrl, magicExtensions) => {\n const urlDirectoryUrl = resolveUrl(\"./\", fileUrl)\n const urlFilename = urlToFilename(fileUrl)\n const extensionLeadingToFile = await firstOperationMatching({\n array: magicExtensions,\n start: async (extensionCandidate) => {\n const urlCandidate = `${urlDirectoryUrl}${urlFilename}${extensionCandidate}`\n const stats = await readFileSystemNodeStat(urlCandidate, { nullIfNotFound: true })\n return stats && stats.isFile() ? extensionCandidate : null\n },\n predicate: (extension) => Boolean(extension),\n })\n return extensionLeadingToFile || null\n}\n", + "import { createDetailedMessage } from \"@jsenv/logger\"\nimport { resolveUrl, readFile, urlToExtension, urlToRelativeUrl } from \"@jsenv/util\"\nimport { normalizeImportMap, resolveImport } from \"@jsenv/import-map\"\nimport {\n memoizeAsyncFunctionByUrl,\n memoizeAsyncFunctionBySpecifierAndImporter,\n} from \"../memoizeAsyncFunction.js\"\nimport { parseSpecifiersFromFile } from \"./parseSpecifiersFromFile.js\"\nimport { showSource } from \"./showSource.js\"\nimport { resolveFile } from \"../resolveFile.js\"\n\nconst BARE_SPECIFIER_ERROR = {}\n\nexport const getImportMapFromJsFiles = async ({\n warn,\n importMap,\n projectDirectoryUrl,\n removeUnusedMappings,\n magicExtensions = [\".js\", \".jsx\", \".ts\", \".tsx\", \".node\", \".json\"],\n}) => {\n const projectPackageFileUrl = resolveUrl(\"./package.json\", projectDirectoryUrl)\n\n const imports = {}\n const scopes = {}\n const addMapping = ({ scope, from, to }) => {\n if (scope) {\n scopes[scope] = {\n ...(scopes[scope] || {}),\n [from]: to,\n }\n } else {\n imports[from] = to\n }\n }\n\n const topLevelMappingsUsed = []\n const scopedMappingsUsed = {}\n const markMappingAsUsed = ({ scope, from, to }) => {\n if (scope) {\n if (scope in scopedMappingsUsed) {\n scopedMappingsUsed[scope].push({ from, to })\n } else {\n scopedMappingsUsed[scope] = [{ from, to }]\n }\n } else {\n topLevelMappingsUsed.push({ from, to })\n }\n }\n const importMapNormalized = normalizeImportMap(importMap, projectDirectoryUrl)\n const trackAndResolveImport = (specifier, importer) => {\n return resolveImport({\n specifier,\n importer,\n importMap: importMapNormalized,\n defaultExtension: false,\n onImportMapping: ({ scope, from }) => {\n markMappingAsUsed({\n scope,\n from,\n to: scope ? importMap.scopes[scope][from] : importMap.imports[from],\n })\n },\n createBareSpecifierError: () => BARE_SPECIFIER_ERROR,\n })\n }\n\n const visitFile = async (specifier, importer, { importedBy }) => {\n let fileUrl\n let gotBareSpecifierError = false\n\n try {\n fileUrl = trackAndResolveImport(specifier, importer)\n } catch (e) {\n if (e !== BARE_SPECIFIER_ERROR) {\n throw e\n }\n gotBareSpecifierError = true\n fileUrl = resolveUrl(specifier, importer)\n }\n\n const fileUrlOnFileSystem = await resolveFile(fileUrl, {\n magicExtensions: magicExtensionWithImporterExtension(magicExtensions, importer),\n })\n\n if (!fileUrlOnFileSystem) {\n warn(\n createFileNotFoundWarning({\n specifier,\n importedBy,\n fileUrl,\n magicExtensions,\n }),\n )\n return\n }\n\n const needsAutoMapping = fileUrlOnFileSystem !== fileUrl || gotBareSpecifierError\n if (needsAutoMapping) {\n const packageDirectoryUrl = packageDirectoryUrlFromUrl(fileUrl, projectDirectoryUrl)\n const packageFileUrl = resolveUrl(\"package.json\", packageDirectoryUrl)\n const autoMapping = {\n scope:\n packageFileUrl === projectPackageFileUrl\n ? undefined\n : `./${urlToRelativeUrl(packageDirectoryUrl, projectDirectoryUrl)}`,\n from: specifier,\n to: `./${urlToRelativeUrl(fileUrlOnFileSystem, projectDirectoryUrl)}`,\n }\n addMapping(autoMapping)\n markMappingAsUsed(autoMapping)\n warn(\n formatAutoMappingSpecifierWarning({\n specifier,\n importedBy,\n autoMapping,\n closestPackageDirectoryUrl: packageDirectoryUrl,\n closestPackageObject: await readFile(packageFileUrl, { as: \"json\" }),\n }),\n )\n }\n\n const fileContent = await readFileContent(fileUrlOnFileSystem)\n const specifiers = await parseSpecifiersFromFile(fileUrlOnFileSystem, { fileContent })\n\n await Promise.all(\n Object.keys(specifiers).map(async (specifier) => {\n const specifierInfo = specifiers[specifier]\n await visitFileMemoized(specifier, fileUrlOnFileSystem, {\n importedBy: showSource({\n url: fileUrlOnFileSystem,\n line: specifierInfo.line,\n column: specifierInfo.column,\n source: fileContent,\n }),\n })\n }),\n )\n }\n const visitFileMemoized = memoizeAsyncFunctionBySpecifierAndImporter(visitFile)\n\n const readFileContent = memoizeAsyncFunctionByUrl((fileUrl) => {\n return readFile(fileUrl, { as: \"string\" })\n })\n\n const projectPackageObject = await readFile(projectPackageFileUrl, { as: \"json\" })\n await visitFileMemoized(projectPackageObject.name, projectPackageFileUrl, {\n importedBy: projectPackageObject.exports\n ? `${projectPackageFileUrl}#exports`\n : `${projectPackageFileUrl}`,\n })\n\n if (removeUnusedMappings) {\n const importsUsed = {}\n topLevelMappingsUsed.forEach(({ from, to }) => {\n importsUsed[from] = to\n })\n const scopesUsed = {}\n Object.keys(scopedMappingsUsed).forEach((scope) => {\n const mappingsUsed = scopedMappingsUsed[scope]\n const scopedMappings = {}\n mappingsUsed.forEach(({ from, to }) => {\n scopedMappings[from] = to\n })\n scopesUsed[scope] = scopedMappings\n })\n return {\n imports: importsUsed,\n scopes: scopesUsed,\n }\n }\n\n return { imports, scopes }\n}\n\nconst packageDirectoryUrlFromUrl = (url, projectDirectoryUrl) => {\n const relativeUrl = urlToRelativeUrl(url, projectDirectoryUrl)\n\n const lastNodeModulesDirectoryStartIndex = relativeUrl.lastIndexOf(\"node_modules/\")\n if (lastNodeModulesDirectoryStartIndex === -1) {\n return projectDirectoryUrl\n }\n\n const lastNodeModulesDirectoryEndIndex =\n lastNodeModulesDirectoryStartIndex + `node_modules/`.length\n\n const beforeNodeModulesLastDirectory = relativeUrl.slice(0, lastNodeModulesDirectoryEndIndex)\n const afterLastNodeModulesDirectory = relativeUrl.slice(lastNodeModulesDirectoryEndIndex)\n const remainingDirectories = afterLastNodeModulesDirectory.split(\"/\")\n\n if (afterLastNodeModulesDirectory[0] === \"@\") {\n // scoped package\n return `${projectDirectoryUrl}${beforeNodeModulesLastDirectory}${remainingDirectories\n .slice(0, 2)\n .join(\"/\")}`\n }\n return `${projectDirectoryUrl}${beforeNodeModulesLastDirectory}${remainingDirectories[0]}/`\n}\n\nconst magicExtensionWithImporterExtension = (magicExtensions, importer) => {\n const importerExtension = urlToExtension(importer)\n const magicExtensionsWithoutImporterExtension = magicExtensions.filter(\n (ext) => ext !== importerExtension,\n )\n return [importerExtension, ...magicExtensionsWithoutImporterExtension]\n}\n\nconst createFileNotFoundWarning = ({ specifier, importedBy, fileUrl, magicExtensions }) => {\n return {\n code: \"FILE_NOT_FOUND\",\n message: createDetailedMessage(`Cannot find file for \"${specifier}\"`, {\n \"specifier origin\": importedBy,\n \"file url tried\": fileUrl,\n ...(urlToExtension(fileUrl) === \"\"\n ? { [\"extensions tried\"]: magicExtensions.join(`, `) }\n : {}),\n }),\n }\n}\n\nconst formatAutoMappingSpecifierWarning = ({\n importedBy,\n autoMapping,\n closestPackageDirectoryUrl,\n closestPackageObject,\n}) => {\n return {\n code: \"AUTO_MAPPING\",\n message: createDetailedMessage(`Auto mapping ${autoMapping.from} to ${autoMapping.to}.`, {\n \"specifier origin\": importedBy,\n \"suggestion\": decideAutoMappingSuggestion({\n autoMapping,\n closestPackageDirectoryUrl,\n closestPackageObject,\n }),\n }),\n }\n}\n\nconst decideAutoMappingSuggestion = ({\n autoMapping,\n closestPackageDirectoryUrl,\n closestPackageObject,\n}) => {\n if (typeof closestPackageObject.importmap === \"string\") {\n const packageImportmapFileUrl = resolveUrl(\n closestPackageObject.importmap,\n closestPackageDirectoryUrl,\n )\n\n return `To get rid of this warning, add an explicit mapping into importmap file.\n${mappingToImportmapString(autoMapping)}\ninto ${packageImportmapFileUrl}.`\n }\n\n return `To get rid of this warning, add an explicit mapping into package.json.\n${mappingToExportsFieldString(autoMapping)}\ninto ${closestPackageDirectoryUrl}package.json.`\n}\n\nconst mappingToImportmapString = ({ scope, from, to }) => {\n if (scope) {\n return JSON.stringify(\n {\n scopes: {\n [scope]: {\n [from]: to,\n },\n },\n },\n null,\n \" \",\n )\n }\n\n return JSON.stringify(\n {\n imports: {\n [from]: to,\n },\n },\n null,\n \" \",\n )\n}\n\nconst mappingToExportsFieldString = ({ scope, from, to }) => {\n if (scope) {\n const scopeUrl = resolveUrl(scope, \"file://\")\n const toUrl = resolveUrl(to, \"file://\")\n to = `./${urlToRelativeUrl(toUrl, scopeUrl)}`\n }\n\n return JSON.stringify(\n {\n exports: {\n [from]: to,\n },\n },\n null,\n \" \",\n )\n}\n", + "export const optimizeImportMap = ({ imports, scopes }) => {\n // remove useless duplicates (scoped key+value already defined on imports)\n const scopesOptimized = {}\n Object.keys(scopes).forEach((scope) => {\n const scopeMappings = scopes[scope]\n const scopeMappingsOptimized = {}\n Object.keys(scopeMappings).forEach((mappingKey) => {\n const topLevelMappingValue = imports[mappingKey]\n const mappingValue = scopeMappings[mappingKey]\n if (!topLevelMappingValue || topLevelMappingValue !== mappingValue) {\n scopeMappingsOptimized[mappingKey] = mappingValue\n }\n })\n if (Object.keys(scopeMappingsOptimized).length > 0) {\n scopesOptimized[scope] = scopeMappingsOptimized\n }\n })\n return { imports, scopes: scopesOptimized }\n}\n", + "import { createDetailedMessage } from \"@jsenv/logger\"\nimport { resolveUrl, urlToFileSystemPath, urlToExtension } from \"@jsenv/util\"\nimport { resolveFile } from \"../resolveFile.js\"\n\nconst magicExtensions = [\".js\", \".json\", \".node\"]\n\nexport const resolvePackageMain = ({\n warn,\n packagesExportsPreference,\n packageFileUrl,\n packageJsonObject,\n}) => {\n if (packagesExportsPreference.includes(\"import\") && \"module\" in packageJsonObject) {\n return resolveMainFile({\n warn,\n packageFileUrl,\n packageMainFieldName: \"module\",\n packageMainFieldValue: packageJsonObject.module,\n })\n }\n\n if (packagesExportsPreference.includes(\"import\") && \"jsnext:main\" in packageJsonObject) {\n return resolveMainFile({\n warn,\n packageFileUrl,\n packageMainFieldName: \"jsnext:main\",\n packageMainFieldValue: packageJsonObject[\"jsnext:main\"],\n })\n }\n\n if (\n packagesExportsPreference.includes(\"browser\") &&\n \"browser\" in packageJsonObject &&\n // when it's an object it means some files\n // should be replaced with an other, let's ignore this when we are searching\n // for the main file\n typeof packageJsonObject.browser === \"string\"\n ) {\n return resolveMainFile({\n warn,\n packageFileUrl,\n packageMainFieldName: \"browser\",\n packageMainFieldValue: packageJsonObject.browser,\n })\n }\n\n if (\"main\" in packageJsonObject) {\n return resolveMainFile({\n warn,\n packageFileUrl,\n packageMainFieldName: \"main\",\n packageMainFieldValue: packageJsonObject.main,\n })\n }\n\n return resolveMainFile({\n warn,\n packageFileUrl,\n packageMainFieldName: \"default\",\n packageMainFieldValue: \"index\",\n })\n}\n\nconst resolveMainFile = async ({\n warn,\n packageFileUrl,\n packageMainFieldName,\n packageMainFieldValue,\n}) => {\n // main is explicitely empty meaning\n // it is assumed that we should not find a file\n if (packageMainFieldValue === \"\") {\n return null\n }\n\n const packageDirectoryUrl = resolveUrl(\"./\", packageFileUrl)\n const mainFileRelativeUrl = packageMainFieldValue.endsWith(\"/\")\n ? `${packageMainFieldValue}index`\n : packageMainFieldValue\n\n const mainFileUrlFirstCandidate = resolveUrl(mainFileRelativeUrl, packageFileUrl)\n\n if (!mainFileUrlFirstCandidate.startsWith(packageDirectoryUrl)) {\n warn(\n createPackageMainFileMustBeRelativeWarning({\n packageMainFieldName,\n packageMainFieldValue,\n packageFileUrl,\n }),\n )\n return null\n }\n\n const mainFileUrl = await resolveFile(mainFileUrlFirstCandidate, {\n magicExtensions,\n })\n\n if (!mainFileUrl) {\n // we know in advance this remapping does not lead to an actual file.\n // we only warn because we have no guarantee this remapping will actually be used\n // in the codebase.\n // warn only if there is actually a main field\n // otherwise the package.json is missing the main field\n // it certainly means it's not important\n if (packageMainFieldName !== \"default\") {\n warn(\n createPackageMainFileNotFoundWarning({\n specifier: packageMainFieldValue,\n importedIn: `${packageFileUrl}#${packageMainFieldName}`,\n fileUrl: mainFileUrlFirstCandidate,\n magicExtensions,\n }),\n )\n }\n return mainFileUrlFirstCandidate\n }\n\n return mainFileUrl\n}\n\nconst createPackageMainFileMustBeRelativeWarning = ({\n packageMainFieldName,\n packageMainFieldValue,\n packageFileUrl,\n}) => {\n return {\n code: \"PACKAGE_MAIN_FILE_MUST_BE_RELATIVE\",\n message: `${packageMainFieldName} field in package.json must be inside package.json folder.\n--- ${packageMainFieldName} ---\n${packageMainFieldValue}\n--- package.json path ---\n${urlToFileSystemPath(packageFileUrl)}`,\n }\n}\n\nconst createPackageMainFileNotFoundWarning = ({\n specifier,\n importedIn,\n fileUrl,\n magicExtensions,\n}) => {\n return {\n code: \"PACKAGE_MAIN_FILE_NOT_FOUND\",\n message: createDetailedMessage(`Cannot find file for \"${specifier}\"`, {\n \"imported in\": importedIn,\n \"file url tried\": fileUrl,\n ...(urlToExtension(fileUrl) === \"\"\n ? { [\"extensions tried\"]: magicExtensions.join(`, `) }\n : {}),\n }),\n }\n}\n", + "import { resolveUrl, moveImportMap } from \"@jsenv/import-map\"\nimport { readFile, urlToFileSystemPath } from \"@jsenv/util\"\n\nexport const visitPackageImportMap = async ({\n warn,\n packageFileUrl,\n packageJsonObject,\n packageImportmap = packageJsonObject.importmap,\n projectDirectoryUrl,\n}) => {\n if (typeof packageImportmap === \"undefined\") {\n return {}\n }\n\n if (typeof packageImportmap === \"string\") {\n const importmapFileUrl = resolveUrl(packageImportmap, packageFileUrl)\n const importmap = await readFile(importmapFileUrl, { as: \"json\" })\n return moveImportMap(importmap, importmapFileUrl, projectDirectoryUrl)\n }\n\n if (typeof packageImportmap === \"object\" && packageImportmap !== null) {\n return packageImportmap\n }\n\n warn(\n createPackageImportMapUnexpectedWarning({\n packageImportmap,\n packageFileUrl,\n }),\n )\n return {}\n}\n\nconst createPackageImportMapUnexpectedWarning = ({ packageImportmap, packageFileUrl }) => {\n return {\n code: \"PACKAGE_IMPORTMAP_UNEXPECTED\",\n message: `unexpected value in package.json importmap field: value must be a string or an object.\n--- value ---\n${packageImportmap}\n--- package.json path ---\n${urlToFileSystemPath(packageFileUrl)}`,\n }\n}\n", "export const specifierIsRelative = (specifier) => {\n if (specifier.startsWith(\"//\")) {\n return false\n }\n if (specifier.startsWith(\"../\")) {\n return false\n }\n // starts with http:// or file:// or ftp: for instance\n if (/^[a-zA-Z]+\\:/.test(specifier)) {\n return false\n }\n return true\n}\n", - "import { urlToFileSystemPath } from \"@jsenv/util\"\nimport { specifierIsRelative } from \"./specifierIsRelative.js\"\n\nexport const visitPackageImports = ({ logger, packageFileUrl, packageJsonObject }) => {\n const importsForPackageImports = {}\n const packageFilePath = urlToFileSystemPath(packageFileUrl)\n\n const { imports: packageImports } = packageJsonObject\n if (typeof packageImports !== \"object\" || packageImports === null) {\n logger.warn(`\nimports of package.json must be an object.\n--- package.json imports ---\n${packageImports}\n--- package.json path ---\n${packageFilePath}\n`)\n return importsForPackageImports\n }\n\n Object.keys(packageImports).forEach((specifier) => {\n if (!specifierIsRelative(specifier)) {\n logger.warn(`\nfound unexpected specifier in imports of package.json, it must be relative to package.json.\n--- specifier ---\n${specifier}\n--- package.json path ---\n${packageFilePath}\n`)\n return\n }\n\n const address = packageImports[specifier]\n if (typeof address !== \"string\") {\n logger.warn(`\nfound unexpected address in imports of package.json, it must be a string.\n--- address ---\n${address}\n--- specifier ---\n${specifier}\n--- package.json path ---\n${packageFilePath}\n`)\n return\n }\n if (!specifierIsRelative(address)) {\n logger.warn(`\nfound unexpected address in imports of package.json, it must be relative to package.json.\n--- address ---\n${address}\n--- specifier ---\n${specifier}\n--- package.json path ---\n${packageFilePath}\n`)\n return\n }\n\n let from\n if (specifier[0] === \"/\") {\n from = specifier\n } else if (specifier.startsWith(\"./\")) {\n from = specifier\n } else {\n from = specifier\n }\n\n const to = address\n\n importsForPackageImports[from] = to\n })\n\n return importsForPackageImports\n}\n", - "// https://nodejs.org/dist/latest-v13.x/docs/api/esm.html#esm_package_exports\n\nimport { urlToFileSystemPath } from \"@jsenv/util\"\nimport { specifierIsRelative } from \"./specifierIsRelative.js\"\n\nexport const visitPackageExports = ({\n logger,\n packageFileUrl,\n packageName,\n packageJsonObject,\n packageInfo: { packageDirectoryRelativeUrl },\n packagesExportsPreference,\n}) => {\n const importsForPackageExports = {}\n\n const packageFilePath = urlToFileSystemPath(packageFileUrl)\n const { exports: packageExports } = packageJsonObject\n\n // false is allowed as laternative to exports: {}\n if (packageExports === false) {\n return importsForPackageExports\n }\n\n const addRemapping = ({ from, to }) => {\n if (from.indexOf(\"*\") === -1) {\n importsForPackageExports[from] = to\n return\n }\n\n if (\n from.endsWith(\"/*\") &&\n to.endsWith(\"/*\") &&\n // ensure ends with '*' AND there is only one '*' occurence\n to.indexOf(\"*\") === to.length - 1\n ) {\n const fromWithouTrailingStar = from.slice(0, -1)\n const toWithoutTrailingStar = to.slice(0, -1)\n importsForPackageExports[fromWithouTrailingStar] = toWithoutTrailingStar\n return\n }\n\n logger.warn(`Ignoring export using \"*\" because it is not supported by importmap.\n--- key ---\n${from}\n--- value ---\n${to}\n--- package.json path ---\n${packageFilePath}\n--- see also ---\nhttps://github.com/WICG/import-maps/issues/232`)\n }\n\n // exports used to indicate the main file\n if (typeof packageExports === \"string\") {\n addRemapping({\n from: packageName,\n to: addressToDestination(packageExports, packageDirectoryRelativeUrl),\n })\n return importsForPackageExports\n }\n\n if (typeof packageExports !== \"object\" || packageExports === null) {\n logger.warn(`\nexports of package.json must be an object.\n--- package.json exports ---\n${packageExports}\n--- package.json path ---\n${packageFilePath}\n`)\n return importsForPackageExports\n }\n\n const packageExportsKeys = Object.keys(packageExports)\n const someSpecifierStartsWithDot = packageExportsKeys.some((key) => key.startsWith(\".\"))\n if (someSpecifierStartsWithDot) {\n const someSpecifierDoesNotStartsWithDot = packageExportsKeys.some((key) => !key.startsWith(\".\"))\n if (someSpecifierDoesNotStartsWithDot) {\n // see https://nodejs.org/dist/latest-v13.x/docs/api/esm.html#esm_exports_sugar\n logger.error(`\nexports of package.json mixes conditional exports and direct exports.\n--- package.json path ---\n${packageFilePath}\n`)\n return importsForPackageExports\n }\n }\n\n packageExportsKeys.forEach((specifier) => {\n if (!specifierIsRelative(specifier)) {\n logger.warn(`\nfound unexpected specifier in exports of package.json, it must be relative to package.json.\n--- specifier ---\n${specifier}\n--- package.json path ---\n${packageFilePath}\n`)\n return\n }\n\n const value = packageExports[specifier]\n let address\n\n if (typeof value === \"object\") {\n address = readFavoredKey(value, packagesExportsPreference)\n\n if (!address) {\n return\n }\n if (typeof address === \"object\") {\n address = readFavoredKey(address, packagesExportsPreference)\n if (!address) {\n return\n }\n }\n } else if (typeof value === \"string\") {\n address = value\n } else {\n logger.warn(`\nfound unexpected address in exports of package.json, it must be a string.\n--- address ---\n${address}\n--- specifier ---\n${specifier}\n--- package.json path ---\n${packageFilePath}\n`)\n return\n }\n\n if (!specifierIsRelative(address)) {\n logger.warn(`\nfound unexpected address in exports of package.json, it must be relative to package.json.\n--- address ---\n${address}\n--- specifier ---\n${specifier}\n--- package.json path ---\n${packageFilePath}\n`)\n return\n }\n\n addRemapping({\n from: specifierToSource(specifier, packageName),\n to: addressToDestination(address, packageDirectoryRelativeUrl),\n })\n })\n\n return importsForPackageExports\n}\n\nconst specifierToSource = (specifier, packageName) => {\n if (specifier === \".\") {\n return packageName\n }\n\n if (specifier[0] === \"/\") {\n return specifier\n }\n\n if (specifier.startsWith(\"./\")) {\n return `${packageName}${specifier.slice(1)}`\n }\n\n return `${packageName}/${specifier}`\n}\n\nconst addressToDestination = (address, packageDirectoryRelativeUrl) => {\n if (address[0] === \"/\") {\n return address\n }\n\n if (address.startsWith(\"./\")) {\n return `./${packageDirectoryRelativeUrl}${address.slice(2)}`\n }\n\n return `./${packageDirectoryRelativeUrl}${address}`\n}\n\nconst readFavoredKey = (object, favoredKeys) => {\n const favoredKey = favoredKeys.find((key) => object.hasOwnProperty(key))\n if (favoredKey) {\n return object[favoredKey]\n }\n\n if (object.hasOwnProperty(\"default\")) {\n return object.default\n }\n\n return undefined\n}\n", - "export const memoizeAsyncFunctionByUrl = (fn) => {\n const cache = {}\n return async (url, ...args) => {\n const promiseFromCache = cache[url]\n if (promiseFromCache) {\n return promiseFromCache\n }\n let _resolve\n let _reject\n const promise = new Promise((resolve, reject) => {\n _resolve = resolve\n _reject = reject\n })\n cache[url] = promise\n let value\n let error\n try {\n value = fn(url, ...args)\n error = false\n } catch (e) {\n value = e\n error = true\n delete cache[url]\n }\n if (error) {\n _reject(error)\n } else {\n _resolve(value)\n }\n return promise\n }\n}\n", + "// https://nodejs.org/dist/latest-v13.x/docs/api/esm.html#esm_package_exports\n\nimport { urlToFileSystemPath, urlToRelativeUrl, resolveUrl } from \"@jsenv/util\"\nimport { specifierIsRelative } from \"./specifierIsRelative.js\"\n\nexport const visitPackageExports = ({\n warn,\n packageFileUrl,\n packageJsonObject,\n packageExports = packageJsonObject.exports,\n packageName = packageJsonObject.name,\n projectDirectoryUrl,\n packagesExportsPreference,\n onExport,\n}) => {\n const packageDirectoryUrl = resolveUrl(\"./\", packageFileUrl)\n const packageDirectoryRelativeUrl = urlToRelativeUrl(packageDirectoryUrl, projectDirectoryUrl)\n\n visitExportsSubpath(packageExports, packagesExportsPreference, {\n onUnexpectedPackageExports: ({ packageExportsValue, packageExportsValuePath }) => {\n warn(\n createExportsValueWarning({\n packageExportsValue,\n packageExportsValuePath,\n packageFileUrl,\n }),\n )\n },\n onMixedPackageExports: ({ packageExportsValue, packageExportsValuePath }) => {\n // see https://nodejs.org/dist/latest-v13.x/docs/api/esm.html#esm_exports_sugar\n warn(\n createExportsMixedWarning({\n packageExportsValue,\n packageExportsValuePath,\n packageFileUrl,\n }),\n )\n },\n onSubpathPackageExport: ({ key, value, valuePath }) => {\n if (!specifierIsRelative(key)) {\n warn(\n createExportsMappingKeyMustBeRelativeWarning({\n key,\n keyPath: valuePath.slice(0, -1),\n packageFileUrl,\n }),\n )\n return\n }\n if (typeof value !== \"string\") {\n warn(\n createExportsMappingValueMustBeAStringWarning({\n value,\n valuePath,\n packageFileUrl,\n }),\n )\n return\n }\n if (!specifierIsRelative(value)) {\n warn(\n createExportsMappingValueMustBeRelativeWarning({\n value,\n valuePath,\n packageFileUrl,\n }),\n )\n return\n }\n\n onExport({\n key: specifierToSource(key, packageName),\n value: addressToDestination(value, packageDirectoryRelativeUrl),\n })\n },\n })\n}\n\nconst visitExportsSubpath = (\n packageExports,\n packageExportsConditions,\n { onUnexpectedPackageExports, onMixedPackageExports, onSubpathPackageExport },\n) => {\n const visitValue = (packageExportsValue, { valuePath }) => {\n // false is allowed as alternative to exports: {}\n if (packageExportsValue === false) {\n return\n }\n\n if (typeof packageExportsValue === \"string\") {\n const firstNonConditionKey = valuePath\n .slice()\n .reverse()\n .find((key) => key.startsWith(\".\"))\n const key = firstNonConditionKey || \".\"\n onSubpathPackageExport({\n value: packageExportsValue,\n valuePath,\n key,\n })\n return\n }\n\n if (typeof packageExportsValue !== \"object\" && packageExportsValue !== null) {\n onUnexpectedPackageExports({\n packageExportsValue,\n packageExportsValuePath: valuePath,\n })\n return\n }\n\n const keys = Object.keys(packageExportsValue)\n const everyKeyDoesNotStartsWithDot = keys.every((key) => !key.startsWith(\".\"))\n if (everyKeyDoesNotStartsWithDot) {\n const bestConditionKey = findBestConditionKey(keys, packageExportsConditions)\n if (!bestConditionKey) {\n return\n }\n const bestExports = packageExportsValue[bestConditionKey]\n visitValue(bestExports, {\n valuePath: [...valuePath, bestConditionKey],\n })\n return\n }\n\n const everyKeyStartsWithDot = keys.every((key) => key.startsWith(\".\"))\n if (everyKeyStartsWithDot) {\n keys.forEach((key) => {\n visitValue(packageExportsValue[key], {\n valuePath: [...valuePath, key],\n })\n })\n return\n }\n\n onMixedPackageExports({\n packageExportsValue,\n packageExportsValuePath: valuePath,\n })\n }\n visitValue(packageExports, {\n valuePath: [\"exports\"],\n })\n}\n\nconst findBestConditionKey = (availableKeys, exportsConditions) => {\n const conditionKey = exportsConditions.find((key) => availableKeys.includes(key))\n if (conditionKey) {\n return conditionKey\n }\n\n if (availableKeys.includes(\"default\")) {\n return \"default\"\n }\n\n return undefined\n}\n\nconst specifierToSource = (specifier, packageName) => {\n if (specifier === \".\") {\n return packageName\n }\n\n if (specifier[0] === \"/\") {\n return specifier\n }\n\n if (specifier.startsWith(\"./\")) {\n return `${packageName}${specifier.slice(1)}`\n }\n\n return `${packageName}/${specifier}`\n}\n\nconst addressToDestination = (address, packageDirectoryRelativeUrl) => {\n if (address[0] === \"/\") {\n return address\n }\n\n if (address.startsWith(\"./\")) {\n return `./${packageDirectoryRelativeUrl}${address.slice(2)}`\n }\n\n return `./${packageDirectoryRelativeUrl}${address}`\n}\n\nconst createExportsValueWarning = ({\n packageExportsValue,\n packageExportsValuePath,\n packageFileUrl,\n}) => {\n return {\n code: \"EXPORTS_VALUE\",\n message: `unexpected value in package.json exports field: value must be an object or a string.\n--- value ---\n${packageExportsValue}\n--- value path ---\n${packageExportsValuePath.join(\".\")}\n--- package.json path ---\n${urlToFileSystemPath(packageFileUrl)}`,\n }\n}\n\nconst createExportsMixedWarning = ({\n packageExportsValue,\n packageExportsValuePath,\n packageFileUrl,\n}) => {\n return {\n code: \"EXPORTS_MIXED\",\n message: `unexpected package.json exports field: cannot mix conditional and subpath exports.\n--- value ---\n${JSON.stringify(packageExportsValue, null, \" \")}\n--- value path ---\n${packageExportsValuePath.join(\".\")}\n--- package.json path ---\n${urlToFileSystemPath(packageFileUrl)}`,\n }\n}\n\nconst createExportsMappingKeyMustBeRelativeWarning = ({ key, keyPath, packageFileUrl }) => {\n return {\n code: \"EXPORTS_MAPPING_KEY_MUST_BE_RELATIVE\",\n message: `unexpected key in package.json exports field: key must be relative.\n--- key ---\n${key}\n--- key path ---\n${keyPath.join(\".\")}\n--- package.json path ---\n${urlToFileSystemPath(packageFileUrl)}`,\n }\n}\n\nconst createExportsMappingValueMustBeAStringWarning = ({ value, valuePath, packageFileUrl }) => {\n return {\n code: \"EXPORTS_MAPPING_VALUE_MUST_BE_A_STRING\",\n message: `unexpected value in package.json exports field: value must be a string.\n--- value ---\n${value}\n--- value path ---\n${valuePath.join(\".\")}\n--- package.json path ---\n${urlToFileSystemPath(packageFileUrl)}`,\n }\n}\n\nconst createExportsMappingValueMustBeRelativeWarning = ({ value, valuePath, packageFileUrl }) => {\n return {\n code: \"EXPORTS_MAPPING_VALUE_MUST_BE_RELATIVE\",\n message: `unexpected value in package.json exports field: value must be relative.\n--- value ---\n${value}\n--- value path ---\n${valuePath.join(\".\")}\n--- package.json path ---\n${urlToFileSystemPath(packageFileUrl)}`,\n }\n}\n", "export const applyPackageManualOverride = (packageObject, packagesManualOverrides) => {\n const { name, version } = packageObject\n const overrideKey = Object.keys(packagesManualOverrides).find((overrideKeyCandidate) => {\n if (name === overrideKeyCandidate) {\n return true\n }\n if (`${name}@${version}` === overrideKeyCandidate) {\n return true\n }\n return false\n })\n if (overrideKey) {\n return composeObject(packageObject, packagesManualOverrides[overrideKey])\n }\n return packageObject\n}\n\nconst composeObject = (leftObject, rightObject) => {\n const composedObject = {\n ...leftObject,\n }\n Object.keys(rightObject).forEach((key) => {\n const rightValue = rightObject[key]\n\n if (rightValue === null || typeof rightValue !== \"object\" || key in leftObject === false) {\n composedObject[key] = rightValue\n } else {\n const leftValue = leftObject[key]\n if (leftValue === null || typeof leftValue !== \"object\") {\n composedObject[key] = rightValue\n } else {\n composedObject[key] = composeObject(leftValue, rightValue)\n }\n }\n })\n return composedObject\n}\n", "import { readFile, urlToFileSystemPath } from \"@jsenv/util\"\nimport { applyPackageManualOverride } from \"./applyPackageManualOverride.js\"\n\nexport const PACKAGE_NOT_FOUND = {}\nexport const PACKAGE_WITH_SYNTAX_ERROR = {}\n\nexport const readPackageFile = async (packageFileUrl, packagesManualOverrides) => {\n try {\n const packageObject = await readFile(packageFileUrl, { as: \"json\" })\n return applyPackageManualOverride(packageObject, packagesManualOverrides)\n } catch (e) {\n if (e.code === \"ENOENT\") {\n return PACKAGE_NOT_FOUND\n }\n\n if (e.name === \"SyntaxError\") {\n console.error(formatPackageSyntaxErrorLog({ syntaxError: e, packageFileUrl }))\n return PACKAGE_WITH_SYNTAX_ERROR\n }\n\n throw e\n }\n}\n\nconst formatPackageSyntaxErrorLog = ({ syntaxError, packageFileUrl }) => {\n return `\nerror while parsing package.json.\n--- syntax error message ---\n${syntaxError.message}\n--- package.json path ---\n${urlToFileSystemPath(packageFileUrl)}\n`\n}\n", - "import { firstOperationMatching } from \"@jsenv/cancellation\"\nimport { urlToRelativeUrl, resolveUrl } from \"@jsenv/util\"\nimport { memoizeAsyncFunctionByUrl } from \"./memoizeAsyncFunctionByUrl.js\"\nimport { readPackageFile, PACKAGE_NOT_FOUND, PACKAGE_WITH_SYNTAX_ERROR } from \"./readPackageFile.js\"\n\nexport const createFindNodeModulePackage = (packagesManualOverrides) => {\n const readPackageFileMemoized = memoizeAsyncFunctionByUrl((packageFileUrl) => {\n return readPackageFile(packageFileUrl, packagesManualOverrides)\n })\n\n return ({ projectDirectoryUrl, packageFileUrl, dependencyName }) => {\n const nodeModuleCandidates = getNodeModuleCandidates(packageFileUrl, projectDirectoryUrl)\n\n return firstOperationMatching({\n array: nodeModuleCandidates,\n start: async (nodeModuleCandidate) => {\n const packageFileUrlCandidate = `${projectDirectoryUrl}${nodeModuleCandidate}${dependencyName}/package.json`\n const packageObjectCandidate = await readPackageFileMemoized(packageFileUrlCandidate)\n return {\n packageFileUrl: packageFileUrlCandidate,\n packageJsonObject: packageObjectCandidate,\n }\n },\n predicate: ({ packageJsonObject }) => {\n return (\n packageJsonObject !== PACKAGE_NOT_FOUND && packageJsonObject !== PACKAGE_WITH_SYNTAX_ERROR\n )\n },\n })\n }\n}\n\nconst getNodeModuleCandidates = (fileUrl, projectDirectoryUrl) => {\n const fileDirectoryUrl = resolveUrl(\"./\", fileUrl)\n\n if (fileDirectoryUrl === projectDirectoryUrl) {\n return [`node_modules/`]\n }\n\n const fileDirectoryRelativeUrl = urlToRelativeUrl(fileDirectoryUrl, projectDirectoryUrl)\n const candidates = []\n const relativeNodeModuleDirectoryArray = fileDirectoryRelativeUrl.split(\"node_modules/\")\n // remove the first empty string\n relativeNodeModuleDirectoryArray.shift()\n\n let i = relativeNodeModuleDirectoryArray.length\n while (i--) {\n candidates.push(\n `node_modules/${relativeNodeModuleDirectoryArray\n .slice(0, i + 1)\n .join(\"node_modules/\")}node_modules/`,\n )\n }\n\n return [...candidates, \"node_modules/\"]\n}\n", - "import { createLogger, createDetailedMessage } from \"@jsenv/logger\"\nimport { moveImportMap, sortImportMap } from \"@jsenv/import-map\"\nimport {\n resolveUrl,\n urlToRelativeUrl,\n assertAndNormalizeDirectoryUrl,\n urlToFileSystemPath,\n urlToBasename,\n readFile,\n} from \"@jsenv/util\"\nimport { resolvePackageMain } from \"./internal/resolvePackageMain.js\"\nimport { visitPackageImports } from \"./internal/visitPackageImports.js\"\nimport { visitPackageExports } from \"./internal/visitPackageExports.js\"\nimport { createFindNodeModulePackage } from \"./internal/node-module-resolution.js\"\n\nexport const getImportMapFromNodeModules = async ({\n // nothing is actually listening for this cancellationToken for now\n // it's not very important but it would be better to register on it\n // an stops what we are doing if asked to do so\n // cancellationToken = createCancellationTokenForProcess(),\n logLevel,\n projectDirectoryUrl,\n rootProjectDirectoryUrl,\n importMapFileRelativeUrl = \"./import-map.importmap\",\n\n projectPackageDevDependenciesIncluded = process.env.NODE_ENV !== \"production\",\n packagesExportsPreference = [\"import\", \"browser\"],\n packagesExportsIncluded = true,\n packagesSelfReference = true,\n packagesImportsIncluded = true,\n packagesManualOverrides = {},\n packageIncludedPredicate = () => true,\n}) => {\n const logger = createLogger({ logLevel })\n\n projectDirectoryUrl = assertAndNormalizeDirectoryUrl(projectDirectoryUrl)\n if (typeof rootProjectDirectoryUrl === \"undefined\") {\n rootProjectDirectoryUrl = projectDirectoryUrl\n } else {\n rootProjectDirectoryUrl = assertAndNormalizeDirectoryUrl(rootProjectDirectoryUrl)\n }\n\n const projectPackageFileUrl = resolveUrl(\"./package.json\", projectDirectoryUrl)\n const rootProjectPackageFileUrl = resolveUrl(\"./package.json\", rootProjectDirectoryUrl)\n const findNodeModulePackage = createFindNodeModulePackage(packagesManualOverrides)\n\n const imports = {}\n const scopes = {}\n const seen = {}\n\n const markPackageAsSeen = (packageFileUrl, importerPackageFileUrl) => {\n if (packageFileUrl in seen) {\n seen[packageFileUrl].push(importerPackageFileUrl)\n } else {\n seen[packageFileUrl] = [importerPackageFileUrl]\n }\n }\n\n const packageIsSeen = (packageFileUrl, importerPackageFileUrl) => {\n return packageFileUrl in seen && seen[packageFileUrl].includes(importerPackageFileUrl)\n }\n\n const visit = async ({\n packageFileUrl,\n packageName,\n packageJsonObject,\n importerPackageFileUrl,\n importerPackageJsonObject,\n includeDevDependencies,\n }) => {\n if (!packageIncludedPredicate({ packageName, packageFileUrl, packageJsonObject })) {\n return\n }\n\n await visitDependencies({\n packageFileUrl,\n packageJsonObject,\n includeDevDependencies,\n })\n await visitPackage({\n packageFileUrl,\n packageName,\n packageJsonObject,\n importerPackageFileUrl,\n importerPackageJsonObject,\n })\n }\n\n const visitPackage = async ({\n packageFileUrl,\n packageName,\n packageJsonObject,\n importerPackageFileUrl,\n importerPackageJsonObject,\n }) => {\n const packageInfo = computePackageInfo({\n packageFileUrl,\n packageName,\n importerPackageFileUrl,\n })\n\n await visitPackageMain({\n packageFileUrl,\n packageName,\n packageJsonObject,\n packageInfo,\n })\n\n if (packagesImportsIncluded && \"imports\" in packageJsonObject) {\n const importsForPackageImports = visitPackageImports({\n logger,\n packageFileUrl,\n packageName,\n packageJsonObject,\n packageInfo,\n })\n\n const { packageIsRoot, packageDirectoryRelativeUrl } = packageInfo\n Object.keys(importsForPackageImports).forEach((from) => {\n const to = importsForPackageImports[from]\n\n if (packageIsRoot) {\n addTopLevelImportMapping({ from, to })\n } else {\n const toScoped =\n to[0] === \"/\"\n ? to\n : `./${packageDirectoryRelativeUrl}${to.startsWith(\"./\") ? to.slice(2) : to}`\n\n addScopedImportMapping({\n scope: `./${packageDirectoryRelativeUrl}`,\n from,\n to: toScoped,\n })\n\n // when a package says './' maps to './'\n // we must add something to say if we are already inside the package\n // no need to ensure leading slash are scoped to the package\n if (from === \"./\" && to === \"./\") {\n addScopedImportMapping({\n scope: `./${packageDirectoryRelativeUrl}`,\n from: `./${packageDirectoryRelativeUrl}`,\n to: `./${packageDirectoryRelativeUrl}`,\n })\n } else if (from === \"/\" && to === \"/\") {\n addScopedImportMapping({\n scope: `./${packageDirectoryRelativeUrl}`,\n from: `./${packageDirectoryRelativeUrl}`,\n to: `./${packageDirectoryRelativeUrl}`,\n })\n }\n }\n })\n }\n\n if (packagesSelfReference) {\n const { packageIsRoot, packageDirectoryRelativeUrl } = packageInfo\n\n // allow import 'package-name/dir/file.js' in package-name files\n if (packageIsRoot) {\n addTopLevelImportMapping({\n from: `${packageName}/`,\n to: `./${packageDirectoryRelativeUrl}`,\n })\n }\n // scoped allow import 'package-name/dir/file.js' in package-name files\n else {\n addScopedImportMapping({\n scope: `./${packageDirectoryRelativeUrl}`,\n from: `${packageName}/`,\n to: `./${packageDirectoryRelativeUrl}`,\n })\n }\n }\n\n if (packagesExportsIncluded && \"exports\" in packageJsonObject) {\n const importsForPackageExports = visitPackageExports({\n logger,\n packageFileUrl,\n packageName,\n packageJsonObject,\n packageInfo,\n packagesExportsPreference,\n })\n\n const {\n importerIsRoot,\n importerRelativeUrl,\n packageIsRoot,\n packageDirectoryRelativeUrl,\n // packageDirectoryUrl,\n // packageDirectoryUrlExpected,\n } = packageInfo\n\n if (packageIsRoot && packagesSelfReference) {\n Object.keys(importsForPackageExports).forEach((from) => {\n const to = importsForPackageExports[from]\n addTopLevelImportMapping({\n from,\n to,\n })\n })\n } else if (packageIsRoot) {\n // ignore exports\n } else {\n Object.keys(importsForPackageExports).forEach((from) => {\n const to = importsForPackageExports[from]\n\n // own package exports available to himself\n if (importerIsRoot) {\n // importer is the package himself, keep exports scoped\n // otherwise the dependency exports would override the package exports.\n if (importerPackageJsonObject.name === packageName) {\n addScopedImportMapping({\n scope: `./${packageDirectoryRelativeUrl}`,\n from,\n to,\n })\n if (from === packageName || from in imports === false) {\n addTopLevelImportMapping({ from, to })\n }\n } else {\n addTopLevelImportMapping({ from, to })\n }\n } else {\n addScopedImportMapping({\n scope: `./${packageDirectoryRelativeUrl}`,\n from,\n to,\n })\n }\n\n // now make package exports available to the importer\n // if importer is root no need because the top level remapping does it\n if (importerIsRoot) {\n return\n }\n\n // now make it available to the importer\n // here if the importer is himself we could do stuff\n // we should even handle the case earlier to prevent top level remapping\n addScopedImportMapping({ scope: `./${importerRelativeUrl}`, from, to })\n })\n }\n }\n }\n\n const visitPackageMain = async ({\n packageFileUrl,\n packageName,\n packageJsonObject,\n packageInfo: {\n importerIsRoot,\n importerRelativeUrl,\n packageIsRoot,\n packageIsProject,\n packageDirectoryUrl,\n packageDirectoryUrlExpected,\n },\n }) => {\n const self = packageIsRoot || packageIsProject\n if (self && !packagesSelfReference) return\n\n const mainFileUrl = await resolvePackageMain({\n packageFileUrl,\n packageJsonObject,\n logger,\n })\n\n // it's possible to have no main\n // like { main: \"\" } in package.json\n // or a main that does not lead to an actual file\n if (mainFileUrl === null) return\n\n const mainFileRelativeUrl = urlToRelativeUrl(mainFileUrl, rootProjectDirectoryUrl)\n const from = packageName\n const to = `./${mainFileRelativeUrl}`\n\n if (importerIsRoot) {\n addTopLevelImportMapping({ from, to })\n } else {\n addScopedImportMapping({ scope: `./${importerRelativeUrl}`, from, to })\n }\n if (packageDirectoryUrl !== packageDirectoryUrlExpected) {\n addScopedImportMapping({ scope: `./${importerRelativeUrl}`, from, to })\n }\n }\n\n const visitDependencies = async ({\n packageFileUrl,\n packageJsonObject,\n includeDevDependencies,\n }) => {\n const dependencyMap = packageDependenciesFromPackageObject(packageJsonObject, {\n includeDevDependencies,\n })\n\n await Promise.all(\n Object.keys(dependencyMap).map(async (dependencyName) => {\n const dependencyInfo = dependencyMap[dependencyName]\n await visitDependency({\n packageFileUrl,\n packageJsonObject,\n dependencyName,\n dependencyInfo,\n })\n }),\n )\n }\n\n const visitDependency = async ({\n packageFileUrl,\n packageJsonObject,\n dependencyName,\n dependencyInfo,\n }) => {\n const dependencyData = await findDependency({\n packageFileUrl,\n dependencyName,\n })\n if (!dependencyData) {\n logger[dependencyInfo.isOptional ? \"debug\" : \"warn\"](\n formatCannotFindPackageLog({\n dependencyName,\n dependencyInfo,\n packageFileUrl,\n }),\n )\n\n return\n }\n\n const {\n packageFileUrl: dependencyPackageFileUrl,\n packageJsonObject: dependencyPackageJsonObject,\n } = dependencyData\n\n if (packageIsSeen(dependencyPackageFileUrl, packageFileUrl)) {\n return\n }\n markPackageAsSeen(dependencyPackageFileUrl, packageFileUrl)\n await visit({\n packageFileUrl: dependencyPackageFileUrl,\n packageName: dependencyName,\n packageJsonObject: dependencyPackageJsonObject,\n importerPackageFileUrl: packageFileUrl,\n importerPackageJsonObject: packageJsonObject,\n })\n }\n\n const computePackageInfo = ({ packageFileUrl, packageName, importerPackageFileUrl }) => {\n const importerIsRoot = importerPackageFileUrl === rootProjectPackageFileUrl\n\n const importerIsProject = importerPackageFileUrl === projectPackageFileUrl\n\n const importerPackageDirectoryUrl = resolveUrl(\"./\", importerPackageFileUrl)\n\n const importerRelativeUrl = importerIsRoot\n ? `${urlToBasename(rootProjectDirectoryUrl.slice(0, -1))}/`\n : urlToRelativeUrl(importerPackageDirectoryUrl, rootProjectDirectoryUrl)\n\n const packageIsRoot = packageFileUrl === rootProjectPackageFileUrl\n\n const packageIsProject = packageFileUrl === projectPackageFileUrl\n\n const packageDirectoryUrl = resolveUrl(\"./\", packageFileUrl)\n\n let packageDirectoryUrlExpected\n if (packageIsProject && !packageIsRoot) {\n packageDirectoryUrlExpected = importerPackageDirectoryUrl\n } else {\n packageDirectoryUrlExpected = `${importerPackageDirectoryUrl}node_modules/${packageName}/`\n }\n\n const packageDirectoryRelativeUrl = urlToRelativeUrl(\n packageDirectoryUrl,\n rootProjectDirectoryUrl,\n )\n\n return {\n importerIsRoot,\n importerIsProject,\n importerRelativeUrl,\n packageIsRoot,\n packageIsProject,\n packageDirectoryUrl,\n packageDirectoryUrlExpected,\n packageDirectoryRelativeUrl,\n }\n }\n\n const addTopLevelImportMapping = ({ from, to }) => {\n // we could think it's useless to remap from with to\n // however it can be used to ensure a weaker remapping\n // does not win over this specific file or folder\n if (from === to) {\n /**\n * however remapping '/' to '/' is truly useless\n * moreover it would make wrapImportMap create something like\n * {\n * imports: {\n * \"/\": \"/.dist/best/\"\n * }\n * }\n * that would append the wrapped folder twice\n * */\n if (from === \"/\") return\n }\n\n imports[from] = to\n }\n\n const addScopedImportMapping = ({ scope, from, to }) => {\n scopes[scope] = {\n ...(scopes[scope] || {}),\n [from]: to,\n }\n }\n\n const dependenciesCache = {}\n const findDependency = ({ packageFileUrl, dependencyName }) => {\n if (packageFileUrl in dependenciesCache === false) {\n dependenciesCache[packageFileUrl] = {}\n }\n if (dependencyName in dependenciesCache[packageFileUrl]) {\n return dependenciesCache[packageFileUrl][dependencyName]\n }\n const dependencyPromise = findNodeModulePackage({\n projectDirectoryUrl: rootProjectDirectoryUrl,\n packageFileUrl,\n dependencyName,\n })\n dependenciesCache[packageFileUrl][dependencyName] = dependencyPromise\n return dependencyPromise\n }\n\n const projectPackageJsonObject = await readFile(projectPackageFileUrl, { as: \"json\" })\n const importerPackageFileUrl = projectPackageFileUrl\n markPackageAsSeen(projectPackageFileUrl, importerPackageFileUrl)\n\n const packageName = projectPackageJsonObject.name\n if (typeof packageName !== \"string\") {\n logger.warn(\n formatUnexpectedPackageNameLog({ packageName, packageFileUrl: projectPackageFileUrl }),\n )\n return {}\n }\n\n await visit({\n packageFileUrl: projectPackageFileUrl,\n packageName: projectPackageJsonObject.name,\n packageJsonObject: projectPackageJsonObject,\n importerPackageFileUrl,\n importerPackageJsonObject: null,\n includeDevDependencies: projectPackageDevDependenciesIncluded,\n })\n\n // remove useless duplicates (scoped key+value already defined on imports)\n Object.keys(scopes).forEach((key) => {\n const scopedImports = scopes[key]\n Object.keys(scopedImports).forEach((scopedImportKey) => {\n if (\n scopedImportKey in imports &&\n imports[scopedImportKey] === scopedImports[scopedImportKey]\n ) {\n delete scopedImports[scopedImportKey]\n }\n })\n if (Object.keys(scopedImports).length === 0) {\n delete scopes[key]\n }\n })\n\n // The importmap generated at this point is relative to the project directory url\n // In other words if you want to use that importmap you have to put it\n // inside projectDirectoryUrl (it cannot be nested in a subdirectory).\n let importMap = { imports, scopes }\n if (importMapFileRelativeUrl) {\n // When there is an importMapFileRelativeUrl we will make remapping relative\n // to the importmap file future location (where user will write it).\n // This allows to put the importmap anywhere inside the projectDirectoryUrl.\n // (If possible prefer to have it top level to avoid too many ../\n const importMapProjectUrl = resolveUrl(\"project.importmap\", projectDirectoryUrl)\n const importMapRealUrl = resolveUrl(importMapFileRelativeUrl, projectDirectoryUrl)\n importMap = moveImportMap(importMap, importMapProjectUrl, importMapRealUrl)\n }\n importMap = sortImportMap(importMap)\n\n return importMap\n}\n\nconst packageDependenciesFromPackageObject = (packageObject, { includeDevDependencies }) => {\n const packageDependencies = {}\n\n const { dependencies = {} } = packageObject\n // https://npm.github.io/using-pkgs-docs/package-json/types/optionaldependencies.html\n const { optionalDependencies = {} } = packageObject\n Object.keys(dependencies).forEach((dependencyName) => {\n packageDependencies[dependencyName] = {\n type: \"dependency\",\n isOptional: dependencyName in optionalDependencies,\n versionPattern: dependencies[dependencyName],\n }\n })\n\n const { peerDependencies = {} } = packageObject\n const { peerDependenciesMeta = {} } = packageObject\n Object.keys(peerDependencies).forEach((dependencyName) => {\n packageDependencies[dependencyName] = {\n type: \"peerDependency\",\n versionPattern: peerDependencies[dependencyName],\n isOptional:\n dependencyName in peerDependenciesMeta && peerDependenciesMeta[dependencyName].optional,\n }\n })\n\n if (includeDevDependencies) {\n const { devDependencies = {} } = packageObject\n Object.keys(devDependencies).forEach((dependencyName) => {\n if (!packageDependencies.hasOwnProperty(dependencyName)) {\n packageDependencies[dependencyName] = {\n type: \"devDependency\",\n versionPattern: devDependencies[dependencyName],\n }\n }\n })\n }\n\n return packageDependencies\n}\n\nconst formatUnexpectedPackageNameLog = ({ packageName, packageFileUrl }) => {\n return `\npackage name field must be a string\n--- package name field ---\n${packageName}\n--- package.json file path ---\n${packageFileUrl}\n`\n}\n\nconst formatCannotFindPackageLog = ({ dependencyName, dependencyInfo, packageFileUrl }) => {\n const dependencyIsOptional = dependencyInfo.isOptional\n const dependencyType = dependencyInfo.type\n const dependencyVersionPattern = dependencyInfo.versionPattern\n const detailedMessage = createDetailedMessage(\n dependencyIsOptional\n ? `cannot find an optional ${dependencyType}.`\n : `cannot find a ${dependencyType}.`,\n {\n [dependencyType]: `${dependencyName}@${dependencyVersionPattern}`,\n \"required by\": urlToFileSystemPath(packageFileUrl),\n },\n )\n return `\n${detailedMessage}\n`\n}\n", - "import { readFile, assertAndNormalizeFileUrl } from \"@jsenv/util\"\n\nexport const getImportMapFromFile = async (importMapFilePath) => {\n const importMapFileUrl = assertAndNormalizeFileUrl(importMapFilePath)\n const importMapFileContent = await readFile(importMapFileUrl)\n const importMap = JSON.parse(importMapFileContent)\n return importMap\n}\n", + "import { firstOperationMatching } from \"@jsenv/cancellation\"\nimport { urlToRelativeUrl, resolveUrl } from \"@jsenv/util\"\nimport { memoizeAsyncFunctionByUrl } from \"../memoizeAsyncFunction.js\"\nimport { readPackageFile, PACKAGE_NOT_FOUND, PACKAGE_WITH_SYNTAX_ERROR } from \"./readPackageFile.js\"\n\nexport const createFindNodeModulePackage = (packagesManualOverrides) => {\n const readPackageFileMemoized = memoizeAsyncFunctionByUrl((packageFileUrl) => {\n return readPackageFile(packageFileUrl, packagesManualOverrides)\n })\n\n return ({ projectDirectoryUrl, packageFileUrl, dependencyName }) => {\n const nodeModuleCandidates = getNodeModuleCandidates(packageFileUrl, projectDirectoryUrl)\n\n return firstOperationMatching({\n array: nodeModuleCandidates,\n start: async (nodeModuleCandidate) => {\n const packageFileUrlCandidate = `${projectDirectoryUrl}${nodeModuleCandidate}${dependencyName}/package.json`\n const packageObjectCandidate = await readPackageFileMemoized(packageFileUrlCandidate)\n return {\n packageFileUrl: packageFileUrlCandidate,\n packageJsonObject: packageObjectCandidate,\n }\n },\n predicate: ({ packageJsonObject }) => {\n return (\n packageJsonObject !== PACKAGE_NOT_FOUND && packageJsonObject !== PACKAGE_WITH_SYNTAX_ERROR\n )\n },\n })\n }\n}\n\nconst getNodeModuleCandidates = (fileUrl, projectDirectoryUrl) => {\n const fileDirectoryUrl = resolveUrl(\"./\", fileUrl)\n\n if (fileDirectoryUrl === projectDirectoryUrl) {\n return [`node_modules/`]\n }\n\n const fileDirectoryRelativeUrl = urlToRelativeUrl(fileDirectoryUrl, projectDirectoryUrl)\n const candidates = []\n const relativeNodeModuleDirectoryArray = fileDirectoryRelativeUrl.split(\"node_modules/\")\n // remove the first empty string\n relativeNodeModuleDirectoryArray.shift()\n\n let i = relativeNodeModuleDirectoryArray.length\n while (i--) {\n candidates.push(\n `node_modules/${relativeNodeModuleDirectoryArray\n .slice(0, i + 1)\n .join(\"node_modules/\")}node_modules/`,\n )\n }\n\n return [...candidates, \"node_modules/\"]\n}\n", + "import { createDetailedMessage } from \"@jsenv/logger\"\nimport {\n resolveUrl,\n urlToRelativeUrl,\n assertAndNormalizeDirectoryUrl,\n urlToFileSystemPath,\n urlToBasename,\n readFile,\n} from \"@jsenv/util\"\nimport { optimizeImportMap } from \"../optimizeImportMap.js\"\nimport { resolvePackageMain } from \"./resolvePackageMain.js\"\nimport { visitPackageImportMap } from \"./visitPackageImportMap.js\"\nimport { visitPackageExports } from \"./visitPackageExports.js\"\nimport { createFindNodeModulePackage } from \"./node-module-resolution.js\"\n\nexport const getImportMapFromPackageFiles = async ({\n // nothing is actually listening for this cancellationToken for now\n // it's not very important but it would be better to register on it\n // an stops what we are doing if asked to do so\n // cancellationToken = createCancellationTokenForProcess(),\n logger,\n warn,\n projectDirectoryUrl,\n projectPackageDevDependenciesIncluded = process.env.NODE_ENV !== \"production\",\n packagesExportsPreference = [\"import\", \"browser\"],\n packagesExportsIncluded = true,\n packagesManualOverrides = {},\n packageIncludedPredicate = () => true,\n}) => {\n projectDirectoryUrl = assertAndNormalizeDirectoryUrl(projectDirectoryUrl)\n\n const projectPackageFileUrl = resolveUrl(\"./package.json\", projectDirectoryUrl)\n const findNodeModulePackage = createFindNodeModulePackage(packagesManualOverrides)\n\n const imports = {}\n const scopes = {}\n const addTopLevelImportMapping = ({ from, to }) => {\n // we could think it's useless to remap from with to\n // however it can be used to ensure a weaker remapping\n // does not win over this specific file or folder\n if (from === to) {\n /**\n * however remapping '/' to '/' is truly useless\n * moreover it would make wrapImportMap create something like\n * {\n * imports: {\n * \"/\": \"/.dist/best/\"\n * }\n * }\n * that would append the wrapped folder twice\n * */\n if (from === \"/\") return\n }\n\n imports[from] = to\n }\n const addScopedImportMapping = ({ scope, from, to }) => {\n // when a package says './' maps to './'\n // we must add something to say if we are already inside the package\n // no need to ensure leading slash are scoped to the package\n if (from === \"./\" && to === scope) {\n addScopedImportMapping({\n scope,\n from: scope,\n to: scope,\n })\n const packageName = scope.slice(scope.lastIndexOf(\"node_modules/\") + `node_modules/`.length)\n addScopedImportMapping({\n scope,\n from: packageName,\n to: scope,\n })\n }\n\n scopes[scope] = {\n ...(scopes[scope] || {}),\n [from]: to,\n }\n }\n\n const seen = {}\n const markPackageAsSeen = (packageFileUrl, importerPackageFileUrl) => {\n if (packageFileUrl in seen) {\n seen[packageFileUrl].push(importerPackageFileUrl)\n } else {\n seen[packageFileUrl] = [importerPackageFileUrl]\n }\n }\n const packageIsSeen = (packageFileUrl, importerPackageFileUrl) => {\n return packageFileUrl in seen && seen[packageFileUrl].includes(importerPackageFileUrl)\n }\n\n const visit = async ({\n packageFileUrl,\n packageName,\n packageJsonObject,\n importerPackageFileUrl,\n importerPackageJsonObject,\n includeDevDependencies,\n }) => {\n if (!packageIncludedPredicate({ packageName, packageFileUrl, packageJsonObject })) {\n return\n }\n\n await visitDependencies({\n packageFileUrl,\n packageJsonObject,\n includeDevDependencies,\n })\n await visitPackage({\n packageFileUrl,\n packageName,\n packageJsonObject,\n importerPackageFileUrl,\n importerPackageJsonObject,\n })\n }\n\n const visitPackage = async ({\n packageFileUrl,\n packageName,\n packageJsonObject,\n importerPackageFileUrl,\n }) => {\n const packageInfo = computePackageInfo({\n packageFileUrl,\n packageName,\n importerPackageFileUrl,\n })\n\n await visitPackageMain({\n packageFileUrl,\n packageName,\n packageJsonObject,\n packageInfo,\n })\n\n const {\n importerIsRoot,\n importerRelativeUrl,\n packageIsRoot,\n packageDirectoryRelativeUrl,\n // packageDirectoryUrl,\n // packageDirectoryUrlExpected,\n } = packageInfo\n\n const addImportMapForPackage = (importMap) => {\n if (packageIsRoot) {\n const { imports = {}, scopes = {} } = importMap\n Object.keys(imports).forEach((from) => {\n addTopLevelImportMapping({\n from,\n to: imports[from],\n })\n })\n Object.keys(scopes).forEach((scope) => {\n const scopeMappings = scopes[scope]\n Object.keys(scopeMappings).forEach((key) => {\n addScopedImportMapping({\n scope,\n from: key,\n to: scopeMappings[key],\n })\n })\n })\n return\n }\n\n const { imports = {}, scopes = {} } = importMap\n const scope = `./${packageDirectoryRelativeUrl}`\n Object.keys(imports).forEach((from) => {\n const to = imports[from]\n const toMoved = moveMappingValue(to, packageFileUrl, projectDirectoryUrl)\n addScopedImportMapping({\n scope,\n from,\n to: toMoved,\n })\n })\n Object.keys(scopes).forEach((scope) => {\n const scopeMappings = scopes[scope]\n const scopeMoved = moveMappingValue(scope, packageFileUrl, projectDirectoryUrl)\n Object.keys(scopeMappings).forEach((key) => {\n const to = scopeMappings[key]\n const toMoved = moveMappingValue(to, packageFileUrl, projectDirectoryUrl)\n addScopedImportMapping({\n scope: scopeMoved,\n from: key,\n to: toMoved,\n })\n })\n })\n }\n\n const addMappingsForPackageAndImporter = (mappings) => {\n if (packageIsRoot) {\n Object.keys(mappings).forEach((from) => {\n const to = mappings[from]\n addTopLevelImportMapping({\n from,\n to,\n })\n })\n return\n }\n\n if (importerIsRoot) {\n // own package mappings available to himself\n Object.keys(mappings).forEach((from) => {\n const to = mappings[from]\n addScopedImportMapping({\n scope: `./${packageDirectoryRelativeUrl}`,\n from,\n to,\n })\n addTopLevelImportMapping({ from, to })\n })\n\n // if importer is root no need to make package mappings available to the importer\n // because they are already on top level mappings\n return\n }\n\n Object.keys(mappings).forEach((from) => {\n const to = mappings[from]\n // own package exports available to himself\n addScopedImportMapping({\n scope: `./${packageDirectoryRelativeUrl}`,\n from,\n to,\n })\n // now make package exports available to the importer\n // here if the importer is himself we could do stuff\n // we should even handle the case earlier to prevent top level remapping\n addScopedImportMapping({\n scope: `./${importerRelativeUrl}`,\n from,\n to,\n })\n })\n }\n\n const importsFromPackageField = await visitPackageImportMap({\n warn,\n packageFileUrl,\n packageJsonObject,\n projectDirectoryUrl,\n })\n addImportMapForPackage(importsFromPackageField)\n\n if (packagesExportsIncluded && \"exports\" in packageJsonObject) {\n const mappingsFromPackageExports = {}\n visitPackageExports({\n warn,\n packageFileUrl,\n packageJsonObject,\n packageName,\n projectDirectoryUrl,\n packagesExportsPreference,\n onExport: ({ key, value }) => {\n const from = key\n const to = value\n\n if (from.indexOf(\"*\") === -1) {\n mappingsFromPackageExports[from] = to\n return\n }\n\n if (\n from.endsWith(\"/*\") &&\n to.endsWith(\"/*\") &&\n // ensure ends with '*' AND there is only one '*' occurence\n to.indexOf(\"*\") === to.length - 1\n ) {\n const fromWithouTrailingStar = from.slice(0, -1)\n const toWithoutTrailingStar = to.slice(0, -1)\n mappingsFromPackageExports[fromWithouTrailingStar] = toWithoutTrailingStar\n return\n }\n\n warn(\n createExportsWildcardIgnoredWarning({\n key,\n value,\n packageFileUrl,\n }),\n )\n },\n })\n addMappingsForPackageAndImporter(mappingsFromPackageExports)\n }\n }\n\n const visitPackageMain = async ({\n packageFileUrl,\n packageName,\n packageJsonObject,\n packageInfo: {\n importerIsRoot,\n importerRelativeUrl,\n packageDirectoryUrl,\n packageDirectoryUrlExpected,\n },\n }) => {\n const mainFileUrl = await resolvePackageMain({\n warn,\n packagesExportsPreference,\n packageFileUrl,\n packageJsonObject,\n })\n\n // it's possible to have no main\n // like { main: \"\" } in package.json\n // or a main that does not lead to an actual file\n if (mainFileUrl === null) {\n return\n }\n\n const mainFileRelativeUrl = urlToRelativeUrl(mainFileUrl, projectDirectoryUrl)\n const from = packageName\n const to = `./${mainFileRelativeUrl}`\n\n if (importerIsRoot) {\n addTopLevelImportMapping({ from, to })\n } else {\n addScopedImportMapping({\n scope: `./${importerRelativeUrl}`,\n from,\n to,\n })\n }\n if (packageDirectoryUrl !== packageDirectoryUrlExpected) {\n addScopedImportMapping({\n scope: `./${importerRelativeUrl}`,\n from,\n to,\n })\n }\n }\n\n const visitDependencies = async ({\n packageFileUrl,\n packageJsonObject,\n includeDevDependencies,\n }) => {\n const dependencyMap = packageDependenciesFromPackageObject(packageJsonObject, {\n includeDevDependencies,\n })\n\n await Promise.all(\n Object.keys(dependencyMap).map(async (dependencyName) => {\n const dependencyInfo = dependencyMap[dependencyName]\n await visitDependency({\n packageFileUrl,\n packageJsonObject,\n dependencyName,\n dependencyInfo,\n })\n }),\n )\n }\n\n const visitDependency = async ({\n packageFileUrl,\n packageJsonObject,\n dependencyName,\n dependencyInfo,\n }) => {\n const dependencyData = await findDependency({\n packageFileUrl,\n dependencyName,\n })\n if (!dependencyData) {\n const cannotFindPackageWarning = createCannotFindPackageWarning({\n dependencyName,\n dependencyInfo,\n packageFileUrl,\n })\n if (dependencyInfo.isOptional) {\n logger.debug(cannotFindPackageWarning.message)\n } else {\n warn(cannotFindPackageWarning)\n }\n\n return\n }\n\n const {\n packageFileUrl: dependencyPackageFileUrl,\n packageJsonObject: dependencyPackageJsonObject,\n } = dependencyData\n\n if (packageIsSeen(dependencyPackageFileUrl, packageFileUrl)) {\n return\n }\n markPackageAsSeen(dependencyPackageFileUrl, packageFileUrl)\n await visit({\n packageFileUrl: dependencyPackageFileUrl,\n packageName: dependencyName,\n packageJsonObject: dependencyPackageJsonObject,\n importerPackageFileUrl: packageFileUrl,\n importerPackageJsonObject: packageJsonObject,\n })\n }\n\n const computePackageInfo = ({ packageFileUrl, packageName, importerPackageFileUrl }) => {\n const importerIsRoot = importerPackageFileUrl === projectPackageFileUrl\n\n const importerPackageDirectoryUrl = resolveUrl(\"./\", importerPackageFileUrl)\n\n const importerRelativeUrl = importerIsRoot\n ? `${urlToBasename(projectDirectoryUrl.slice(0, -1))}/`\n : urlToRelativeUrl(importerPackageDirectoryUrl, projectDirectoryUrl)\n\n const packageIsRoot = packageFileUrl === projectPackageFileUrl\n\n const packageDirectoryUrl = resolveUrl(\"./\", packageFileUrl)\n\n const packageDirectoryUrlExpected = `${importerPackageDirectoryUrl}node_modules/${packageName}/`\n\n const packageDirectoryRelativeUrl = urlToRelativeUrl(packageDirectoryUrl, projectDirectoryUrl)\n\n return {\n importerIsRoot,\n importerRelativeUrl,\n packageIsRoot,\n packageDirectoryUrl,\n packageDirectoryUrlExpected,\n packageDirectoryRelativeUrl,\n }\n }\n\n const dependenciesCache = {}\n const findDependency = ({ packageFileUrl, dependencyName }) => {\n if (packageFileUrl in dependenciesCache === false) {\n dependenciesCache[packageFileUrl] = {}\n }\n if (dependencyName in dependenciesCache[packageFileUrl]) {\n return dependenciesCache[packageFileUrl][dependencyName]\n }\n const dependencyPromise = findNodeModulePackage({\n projectDirectoryUrl,\n packageFileUrl,\n dependencyName,\n })\n dependenciesCache[packageFileUrl][dependencyName] = dependencyPromise\n return dependencyPromise\n }\n\n const projectPackageJsonObject = await readFile(projectPackageFileUrl, { as: \"json\" })\n const importerPackageFileUrl = projectPackageFileUrl\n markPackageAsSeen(projectPackageFileUrl, importerPackageFileUrl)\n\n const packageName = projectPackageJsonObject.name\n if (typeof packageName !== \"string\") {\n warn(\n createPackageNameMustBeAStringWarning({\n packageName,\n packageFileUrl: projectPackageFileUrl,\n }),\n )\n return {}\n }\n\n await visit({\n packageFileUrl: projectPackageFileUrl,\n packageName: projectPackageJsonObject.name,\n packageJsonObject: projectPackageJsonObject,\n importerPackageFileUrl,\n importerPackageJsonObject: null,\n includeDevDependencies: projectPackageDevDependenciesIncluded,\n })\n\n return optimizeImportMap({ imports, scopes })\n}\n\nconst packageDependenciesFromPackageObject = (packageObject, { includeDevDependencies }) => {\n const packageDependencies = {}\n\n const { dependencies = {} } = packageObject\n // https://npm.github.io/using-pkgs-docs/package-json/types/optionaldependencies.html\n const { optionalDependencies = {} } = packageObject\n Object.keys(dependencies).forEach((dependencyName) => {\n packageDependencies[dependencyName] = {\n type: \"dependency\",\n isOptional: dependencyName in optionalDependencies,\n versionPattern: dependencies[dependencyName],\n }\n })\n\n const { peerDependencies = {} } = packageObject\n const { peerDependenciesMeta = {} } = packageObject\n Object.keys(peerDependencies).forEach((dependencyName) => {\n packageDependencies[dependencyName] = {\n type: \"peerDependency\",\n versionPattern: peerDependencies[dependencyName],\n isOptional:\n dependencyName in peerDependenciesMeta && peerDependenciesMeta[dependencyName].optional,\n }\n })\n\n if (includeDevDependencies) {\n const { devDependencies = {} } = packageObject\n Object.keys(devDependencies).forEach((dependencyName) => {\n if (!packageDependencies.hasOwnProperty(dependencyName)) {\n packageDependencies[dependencyName] = {\n type: \"devDependency\",\n versionPattern: devDependencies[dependencyName],\n }\n }\n })\n }\n\n return packageDependencies\n}\n\nconst moveMappingValue = (address, from, to) => {\n const url = resolveUrl(address, from)\n const relativeUrl = urlToRelativeUrl(url, to)\n if (relativeUrl.startsWith(\"../\")) {\n return relativeUrl\n }\n if (relativeUrl.startsWith(\"./\")) {\n return relativeUrl\n }\n if (/^[a-zA-Z]{2,}:/.test(relativeUrl)) {\n // has sheme\n return relativeUrl\n }\n return `./${relativeUrl}`\n}\n\nconst createExportsWildcardIgnoredWarning = ({ key, value, packageFileUrl }) => {\n return {\n code: \"EXPORTS_WILDCARD\",\n message: `Ignoring export using \"*\" because it is not supported by importmap.\n--- key ---\n${key}\n--- value ---\n${value}\n--- package.json path ---\n${urlToFileSystemPath(packageFileUrl)}\n--- see also ---\nhttps://github.com/WICG/import-maps/issues/232`,\n }\n}\n\nconst createPackageNameMustBeAStringWarning = ({ packageName, packageFileUrl }) => {\n return {\n code: \"PACKAGE_NAME_MUST_BE_A_STRING\",\n message: `package name field must be a string\n--- package name field ---\n${packageName}\n--- package.json file path ---\n${packageFileUrl}`,\n }\n}\n\nconst createCannotFindPackageWarning = ({ dependencyName, dependencyInfo, packageFileUrl }) => {\n const dependencyIsOptional = dependencyInfo.isOptional\n const dependencyType = dependencyInfo.type\n const dependencyVersionPattern = dependencyInfo.versionPattern\n return {\n code: \"CANNOT_FIND_PACKAGE\",\n message: createDetailedMessage(\n dependencyIsOptional\n ? `cannot find an optional ${dependencyType}.`\n : `cannot find a ${dependencyType}.`,\n {\n [dependencyType]: `${dependencyName}@${dependencyVersionPattern}`,\n \"required by\": urlToFileSystemPath(packageFileUrl),\n },\n ),\n }\n}\n", + "import { sortImportMap, composeTwoImportMaps } from \"@jsenv/import-map\"\nimport { createLogger } from \"@jsenv/logger\"\nimport { getImportMapFromJsFiles } from \"./internal/from-js/getImportMapFromJsFiles.js\"\nimport { getImportMapFromPackageFiles } from \"./internal/from-package/getImportMapFromPackageFiles.js\"\n\nexport const getImportMapFromProjectFiles = async ({\n logLevel,\n projectDirectoryUrl,\n runtime = \"browser\",\n moduleFormat = \"esm\",\n dev = false,\n jsFiles = false,\n removeUnusedMappings = !dev,\n magicExtensions,\n onWarn = (warning, warn) => {\n warn(warning)\n },\n ...rest\n}) => {\n const packagesExportsPreference = [\n ...(moduleFormatPreferences[moduleFormat] || [moduleFormat]),\n ...(runtimeExportsPreferences[runtime] || [runtime]),\n ...(dev ? \"development\" : \"production\"),\n ]\n\n const logger = createLogger({ logLevel })\n const warn = (warning) => {\n onWarn(warning, () => {\n logger.warn(`\\n${warning.message}\\n`)\n })\n }\n\n // At this point, importmap is relative to the project directory url\n let importMapFromPackageFiles = await getImportMapFromPackageFiles({\n logger,\n warn,\n projectDirectoryUrl,\n packagesExportsPreference,\n projectPackageDevDependenciesIncluded: dev,\n ...rest,\n })\n importMapFromPackageFiles = sortImportMap(importMapFromPackageFiles)\n\n let importMapFromJsFiles = jsFiles\n ? await getImportMapFromJsFiles({\n logLevel,\n warn,\n importMap: importMapFromPackageFiles,\n removeUnusedMappings,\n projectDirectoryUrl,\n magicExtensions,\n packagesExportsPreference,\n runtime,\n })\n : {}\n importMapFromJsFiles = sortImportMap(importMapFromJsFiles)\n\n return sortImportMap(composeTwoImportMaps(importMapFromPackageFiles, importMapFromJsFiles))\n}\n\nconst runtimeExportsPreferences = {\n browser: [\"browser\"],\n node: [\"node\"],\n}\n\nconst moduleFormatPreferences = {\n esm: [\"import\"],\n cjs: [\"require\"],\n}\n", + "import { assertAndNormalizeDirectoryUrl, resolveUrl, readFile } from \"@jsenv/util\"\nimport { moveImportMap, sortImportMap } from \"@jsenv/import-map\"\n\nexport const getImportMapFromFile = async ({ projectDirectoryUrl, importMapFileRelativeUrl }) => {\n projectDirectoryUrl = assertAndNormalizeDirectoryUrl(projectDirectoryUrl)\n\n const importmapFileUrl = resolveUrl(importMapFileRelativeUrl, projectDirectoryUrl)\n const importmap = await readFile(importmapFileUrl, { as: \"json\" })\n\n // ensure the importmap is now relative to the project directory url\n // we do that because writeImportMapFile expect all importmap\n // to be relative to the projectDirectoryUrl\n const importmapFakeRootUrl = resolveUrl(\"whatever.importmap\", projectDirectoryUrl)\n const importmapRelativeToProject = moveImportMap(\n importmap,\n importmapFileUrl,\n importmapFakeRootUrl,\n )\n\n return sortImportMap(importmapRelativeToProject)\n}\n", "export const importMapToVsCodeConfigPaths = ({ imports = {} }) => {\n const paths = {}\n\n Object.keys(imports).forEach((importKey) => {\n const importValue = imports[importKey]\n\n let key\n if (importKey.endsWith(\"/\")) {\n key = `${importKey}*`\n } else {\n key = importKey\n }\n\n const importValueArray = typeof importValue === \"string\" ? [importValue] : importValue\n const candidatesForPath = importValueArray.map((importValue) => {\n if (importValue.endsWith(\"/\")) {\n return `${importValue}*`\n }\n return importValue\n })\n\n if (key in paths) {\n paths[key] = [...paths[key], ...candidatesForPath]\n } else {\n paths[key] = candidatesForPath\n }\n })\n\n return paths\n}\n", - "import {\n resolveUrl,\n urlToFileSystemPath,\n assertAndNormalizeDirectoryUrl,\n writeFile,\n} from \"@jsenv/util\"\nimport { composeTwoImportMaps } from \"@jsenv/import-map\"\nimport { importMapToVsCodeConfigPaths } from \"./internal/importMapToVsCodeConfigPaths.js\"\n\nexport const generateImportMapForProject = async (\n importMapInputs = [],\n {\n projectDirectoryUrl,\n\n importMapFile = true, // in case someone wants the importmap but not write it on filesystem\n importMapFileRelativeUrl = \"./import-map.importmap\",\n importMapFileLog = true,\n\n jsConfigFile = false, // not yet documented, makes vscode aware of the import remapping\n jsConfigFileLog = true,\n jsConfigLeadingSlash = false,\n jsConfigBase = {},\n },\n) => {\n projectDirectoryUrl = assertAndNormalizeDirectoryUrl(projectDirectoryUrl)\n\n if (importMapInputs.length === 0) {\n console.warn(`importMapInputs is empty, the generated importmap will be empty`)\n }\n\n const importMaps = await Promise.all(importMapInputs)\n\n const importMap = importMaps.reduce((previous, current) => {\n return composeTwoImportMaps(previous, current)\n }, {})\n\n if (importMapFile) {\n const importMapFileUrl = resolveUrl(importMapFileRelativeUrl, projectDirectoryUrl)\n await writeFile(importMapFileUrl, JSON.stringify(importMap, null, \" \"))\n if (importMapFileLog) {\n console.info(`-> ${urlToFileSystemPath(importMapFileUrl)}`)\n }\n }\n if (jsConfigFile) {\n const jsConfigFileUrl = resolveUrl(\"./jsconfig.json\", projectDirectoryUrl)\n try {\n const jsConfig = {\n compilerOptions: {\n baseUrl: \".\",\n ...jsConfigBase,\n paths: {\n ...(jsConfigLeadingSlash ? { \"/*\": [\"./*\"] } : {}),\n ...importMapToVsCodeConfigPaths(importMap),\n },\n },\n }\n await writeFile(jsConfigFileUrl, JSON.stringify(jsConfig, null, \" \"))\n if (jsConfigFileLog) {\n console.info(`-> ${urlToFileSystemPath(jsConfigFileUrl)}`)\n }\n } catch (e) {\n if (e.code !== \"ENOENT\") {\n throw e\n }\n }\n }\n\n return importMap\n}\n" + "import {\n resolveUrl,\n urlToFileSystemPath,\n assertAndNormalizeDirectoryUrl,\n writeFile,\n} from \"@jsenv/util\"\nimport { composeTwoImportMaps } from \"@jsenv/import-map\"\nimport { importMapToVsCodeConfigPaths } from \"./internal/importMapToVsCodeConfigPaths.js\"\n\nexport const writeImportMapFile = async (\n importMapInputs = [],\n {\n projectDirectoryUrl,\n\n importMapFile = true, // in case someone wants the importmap but not write it on filesystem\n importMapFileRelativeUrl = \"./import-map.importmap\",\n importMapFileLog = true,\n\n jsConfigFile = false, // not yet documented, makes vscode aware of the import remapping\n jsConfigFileLog = true,\n jsConfigLeadingSlash = false,\n jsConfigBase = {},\n },\n) => {\n projectDirectoryUrl = assertAndNormalizeDirectoryUrl(projectDirectoryUrl)\n\n if (importMapInputs.length === 0) {\n console.warn(`importMapInputs is empty, the generated importmap will be empty`)\n }\n\n const importMaps = await Promise.all(importMapInputs)\n\n const importMap = importMaps.reduce((previous, current) => {\n return composeTwoImportMaps(previous, current)\n }, {})\n\n if (importMapFile) {\n const importMapFileUrl = resolveUrl(importMapFileRelativeUrl, projectDirectoryUrl)\n await writeFile(importMapFileUrl, JSON.stringify(importMap, null, \" \"))\n if (importMapFileLog) {\n console.info(`-> ${urlToFileSystemPath(importMapFileUrl)}`)\n }\n }\n if (jsConfigFile) {\n const jsConfigFileUrl = resolveUrl(\"./jsconfig.json\", projectDirectoryUrl)\n try {\n const jsConfig = {\n compilerOptions: {\n baseUrl: \".\",\n ...jsConfigBase,\n paths: {\n ...(jsConfigLeadingSlash ? { \"/*\": [\"./*\"] } : {}),\n ...importMapToVsCodeConfigPaths(importMap),\n },\n },\n }\n await writeFile(jsConfigFileUrl, JSON.stringify(jsConfig, null, \" \"))\n if (jsConfigFileLog) {\n console.info(`-> ${urlToFileSystemPath(jsConfigFileUrl)}`)\n }\n } catch (e) {\n if (e.code !== \"ENOENT\") {\n throw e\n }\n }\n }\n\n return importMap\n}\n" ], "names": [ - "resolveFile", + "memoizeAsyncFunctionByUrl", + "fn", + "cache", + "memoizeAsyncFunction", + "getMemoryEntryFromArguments", + "url", + "get", + "set", + "promise", + "delete", + "memoizeAsyncFunctionBySpecifierAndImporter", + "importerCache", + "specifier", + "importer", + "specifierCacheForImporter", + "args", + "memoryEntry", + "promiseFromMemory", + "_resolve", + "_reject", + "Promise", + "resolve", + "reject", + "value", + "error", + "e", + "filenameContainsBackSlashes", + "__filename", + "indexOf", + "replace", + "require", + "createRequire", + "parser", + "traverse", + "parseSpecifiersFromFile", "fileUrl", + "fileContent", + "sourceType", + "allowImportExportEverywhere", + "allowAwaitOutsideFunction", + "ranges", + "jsx", + "typescript", + "flow", + "options", + "undefined", + "readFile", + "as", + "ast", + "parse", + "sourceFilename", + "urlToFileSystemPath", + "plugins", + "specifiers", + "addSpecifier", + "path", + "type", + "node", + "line", + "loc", + "start", + "column", + "default", + "CallExpression", + "callee", + "arguments", + "ExportAllDeclaration", + "ExportNamedDeclaration", + "source", + "ImportDeclaration", + "showSource", + "message", + "showSourceLocation", + "red", + "grey", + "ansiResetSequence", + "numberOfSurroundingLinesToShow", + "lineMaxLength", + "color", + "markColor", + "asideColor", + "colorMark", + "string", + "colorAside", + "mark", + "aside", + "lines", + "split", + "lineRange", + "end", + "moveLineRangeUp", + "moveLineRangeDown", + "lineRangeWithinLines", + "linesToShow", + "slice", + "endLineNumber", + "lineNumberMaxWidth", + "String", + "length", + "columnRange", + "Math", + "floor", + "ceil", + "map", + "lineSource", + "index", + "lineNumber", + "isMainLine", + "lineSourceTruncated", + "applyColumnRange", + "lineNumberWidth", + "lineNumberRightSpacing", + "repeat", + "asideSource", + "lineFormatted", + "lineSourceUntilColumn", + "spacing", + "stringToSpaces", + "mainLineFormatted", + "join", + "TypeError", + "Error", + "prefix", + "suffix", + "lastIndex", + "startTruncated", + "endTruncated", + "from", + "to", + "result", + "number", + "resolveFile", "magicExtensions", "fileStat", "readFileSystemNodeStat", @@ -47,101 +189,161 @@ "findExtensionLeadingToFile", "extension", "urlToExtension", - "fileDirectoryUrl", + "urlDirectoryUrl", "resolveUrl", - "fileBasename", - "urlToBasename", + "urlFilename", + "urlToFilename", "extensionLeadingToFile", "firstOperationMatching", "array", - "start", "extensionCandidate", - "filePathCandidate", + "urlCandidate", "stats", "predicate", "Boolean", - "resolvePackageMain", - "logger", + "BARE_SPECIFIER_ERROR", + "getImportMapFromJsFiles", + "warn", + "importMap", + "projectDirectoryUrl", + "removeUnusedMappings", + "projectPackageFileUrl", + "imports", + "scopes", + "addMapping", + "scope", + "topLevelMappingsUsed", + "scopedMappingsUsed", + "markMappingAsUsed", + "push", + "importMapNormalized", + "normalizeImportMap", + "trackAndResolveImport", + "resolveImport", + "defaultExtension", + "onImportMapping", + "createBareSpecifierError", + "visitFile", + "importedBy", + "gotBareSpecifierError", + "fileUrlOnFileSystem", + "magicExtensionWithImporterExtension", + "createFileNotFoundWarning", + "needsAutoMapping", + "packageDirectoryUrl", + "packageDirectoryUrlFromUrl", "packageFileUrl", + "autoMapping", + "urlToRelativeUrl", + "formatAutoMappingSpecifierWarning", + "closestPackageDirectoryUrl", + "closestPackageObject", + "readFileContent", + "all", + "Object", + "keys", + "specifierInfo", + "visitFileMemoized", + "projectPackageObject", + "name", + "exports", + "importsUsed", + "forEach", + "scopesUsed", + "mappingsUsed", + "scopedMappings", + "relativeUrl", + "lastNodeModulesDirectoryStartIndex", + "lastIndexOf", + "lastNodeModulesDirectoryEndIndex", + "beforeNodeModulesLastDirectory", + "afterLastNodeModulesDirectory", + "remainingDirectories", + "importerExtension", + "magicExtensionsWithoutImporterExtension", + "filter", + "ext", + "code", + "createDetailedMessage", + "decideAutoMappingSuggestion", + "importmap", + "packageImportmapFileUrl", + "mappingToImportmapString", + "mappingToExportsFieldString", + "JSON", + "stringify", + "scopeUrl", + "toUrl", + "optimizeImportMap", + "scopesOptimized", + "scopeMappings", + "scopeMappingsOptimized", + "mappingKey", + "topLevelMappingValue", + "mappingValue", + "resolvePackageMain", + "packagesExportsPreference", "packageJsonObject", + "includes", "resolveMainFile", "packageMainFieldName", "packageMainFieldValue", "module", + "browser", "main", - "packageFilePath", - "urlToFileSystemPath", - "packageDirectoryUrl", "mainFileRelativeUrl", "mainFileUrlFirstCandidate", "startsWith", - "warn", + "createPackageMainFileMustBeRelativeWarning", "mainFileUrl", - "formatFileNotFoundLog", - "specifier", + "createPackageMainFileNotFoundWarning", "importedIn", - "createDetailedMessage", - "join", + "visitPackageImportMap", + "packageImportmap", + "importmapFileUrl", + "moveImportMap", + "createPackageImportMapUnexpectedWarning", "specifierIsRelative", "test", - "visitPackageImports", - "importsForPackageImports", - "imports", - "packageImports", - "Object", - "keys", - "forEach", - "address", - "from", - "to", "visitPackageExports", + "packageExports", "packageName", - "packageInfo", + "onExport", "packageDirectoryRelativeUrl", - "packagesExportsPreference", - "importsForPackageExports", - "exports", - "packageExports", - "addRemapping", - "indexOf", - "length", - "fromWithouTrailingStar", - "slice", - "toWithoutTrailingStar", - "addressToDestination", - "packageExportsKeys", - "someSpecifierStartsWithDot", - "some", + "visitExportsSubpath", + "onUnexpectedPackageExports", + "packageExportsValue", + "packageExportsValuePath", + "createExportsValueWarning", + "onMixedPackageExports", + "createExportsMixedWarning", + "onSubpathPackageExport", "key", - "someSpecifierDoesNotStartsWithDot", - "error", - "value", - "readFavoredKey", + "valuePath", + "createExportsMappingKeyMustBeRelativeWarning", + "keyPath", + "createExportsMappingValueMustBeAStringWarning", + "createExportsMappingValueMustBeRelativeWarning", "specifierToSource", - "object", - "favoredKeys", - "favoredKey", + "addressToDestination", + "packageExportsConditions", + "visitValue", + "firstNonConditionKey", + "reverse", "find", - "hasOwnProperty", - "default", - "undefined", - "memoizeAsyncFunctionByUrl", - "fn", - "cache", - "url", - "args", - "promiseFromCache", - "_resolve", - "_reject", - "promise", - "Promise", - "resolve", - "reject", - "e", + "everyKeyDoesNotStartsWithDot", + "every", + "bestConditionKey", + "findBestConditionKey", + "bestExports", + "everyKeyStartsWithDot", + "availableKeys", + "exportsConditions", + "conditionKey", + "address", "applyPackageManualOverride", "packageObject", "packagesManualOverrides", - "name", "version", "overrideKey", "overrideKeyCandidate", @@ -154,119 +356,118 @@ "PACKAGE_NOT_FOUND", "PACKAGE_WITH_SYNTAX_ERROR", "readPackageFile", - "readFile", - "as", - "code", "console", "formatPackageSyntaxErrorLog", "syntaxError", - "message", "createFindNodeModulePackage", "readPackageFileMemoized", - "projectDirectoryUrl", "dependencyName", "nodeModuleCandidates", "getNodeModuleCandidates", "nodeModuleCandidate", "packageFileUrlCandidate", "packageObjectCandidate", + "fileDirectoryUrl", "fileDirectoryRelativeUrl", - "urlToRelativeUrl", "candidates", "relativeNodeModuleDirectoryArray", - "split", "shift", "i", - "push", - "getImportMapFromNodeModules", - "logLevel", - "rootProjectDirectoryUrl", - "importMapFileRelativeUrl", + "getImportMapFromPackageFiles", + "logger", "projectPackageDevDependenciesIncluded", "packagesExportsIncluded", - "packagesSelfReference", - "packagesImportsIncluded", "packageIncludedPredicate", - "createLogger", "assertAndNormalizeDirectoryUrl", - "projectPackageFileUrl", - "rootProjectPackageFileUrl", "findNodeModulePackage", - "scopes", + "addTopLevelImportMapping", + "addScopedImportMapping", "seen", "markPackageAsSeen", "importerPackageFileUrl", "packageIsSeen", - "includes", "visit", "importerPackageJsonObject", "includeDevDependencies", "visitDependencies", "visitPackage", + "packageInfo", "computePackageInfo", "visitPackageMain", - "packageIsRoot", - "addTopLevelImportMapping", - "toScoped", - "addScopedImportMapping", - "scope", "importerIsRoot", "importerRelativeUrl", - "packageIsProject", + "packageIsRoot", + "addImportMapForPackage", + "toMoved", + "moveMappingValue", + "scopeMoved", + "addMappingsForPackageAndImporter", + "mappings", + "importsFromPackageField", + "mappingsFromPackageExports", + "fromWithouTrailingStar", + "toWithoutTrailingStar", + "createExportsWildcardIgnoredWarning", "packageDirectoryUrlExpected", - "self", "dependencyMap", "packageDependenciesFromPackageObject", - "all", - "map", "dependencyInfo", "visitDependency", "dependencyData", "findDependency", + "cannotFindPackageWarning", + "createCannotFindPackageWarning", "isOptional", - "formatCannotFindPackageLog", + "debug", "dependencyPackageFileUrl", "dependencyPackageJsonObject", - "importerIsProject", "importerPackageDirectoryUrl", + "urlToBasename", "dependenciesCache", "dependencyPromise", "projectPackageJsonObject", - "formatUnexpectedPackageNameLog", - "scopedImports", - "scopedImportKey", - "importMap", - "importMapProjectUrl", - "importMapRealUrl", - "moveImportMap", - "sortImportMap", + "createPackageNameMustBeAStringWarning", "packageDependencies", "dependencies", "optionalDependencies", - "type", "versionPattern", "peerDependencies", "peerDependenciesMeta", "optional", "devDependencies", + "hasOwnProperty", "dependencyIsOptional", "dependencyType", "dependencyVersionPattern", - "detailedMessage", + "getImportMapFromProjectFiles", + "logLevel", + "runtime", + "moduleFormat", + "dev", + "jsFiles", + "onWarn", + "warning", + "rest", + "moduleFormatPreferences", + "runtimeExportsPreferences", + "createLogger", + "importMapFromPackageFiles", + "sortImportMap", + "importMapFromJsFiles", + "composeTwoImportMaps", + "esm", + "cjs", "getImportMapFromFile", - "importMapFilePath", - "importMapFileUrl", - "assertAndNormalizeFileUrl", - "importMapFileContent", - "JSON", - "parse", + "importMapFileRelativeUrl", + "importmapFakeRootUrl", + "importmapRelativeToProject", "importMapToVsCodeConfigPaths", "paths", "importKey", "importValue", "importValueArray", "candidatesForPath", - "generateImportMapForProject", + "writeImportMapFile", "importMapInputs", "importMapFile", "importMapFileLog", @@ -278,14 +479,13 @@ "reduce", "previous", "current", - "composeTwoImportMaps", + "importMapFileUrl", "writeFile", - "stringify", "info", "jsConfigFileUrl", "jsConfig", "compilerOptions", "baseUrl" ], - "mappings": ";;;;;;;;;AAGO,MAAMA,WAAW,GAAG,OAAOC,OAAP,EAAgB;AAAEC,EAAAA;AAAF,CAAhB,KAAwC;AACjE,QAAMC,QAAQ,GAAG,MAAMC,2BAAsB,CAACH,OAAD,EAAU;AACrDI,IAAAA,cAAc,EAAE;AADqC,GAAV,CAA7C,CADiE;;AAMjE,MAAIF,QAAQ,IAAIA,QAAQ,CAACG,MAAT,EAAhB,EAAmC;AACjC,WAAOL,OAAP;AACD,GARgE;;;AAWjE,MAAIE,QAAQ,IAAIA,QAAQ,CAACI,WAAT,EAAhB,EAAwC;AACtC,UAAMC,eAAe,GAAGP,OAAO,CAACQ,QAAR,CAAiB,GAAjB,IAAwB,OAAxB,GAAkC,QAA1D;AACA,UAAMC,YAAY,GAAI,GAAET,OAAQ,GAAEO,eAAgB,EAAlD;AACA,UAAMG,uBAAuB,GAAG,MAAMC,0BAA0B,CAACF,YAAD,EAAeR,eAAf,CAAhE;;AACA,QAAIS,uBAAuB,KAAK,IAAhC,EAAsC;AACpC,aAAO,IAAP;AACD;;AACD,WAAQ,GAAED,YAAa,IAAGC,uBAAwB,EAAlD;AACD,GAnBgE;;;AAsBjE,QAAME,SAAS,GAAGC,mBAAc,CAACb,OAAD,CAAhC;;AACA,MAAIY,SAAS,KAAK,EAAlB,EAAsB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;;" } \ No newline at end of file diff --git a/package.json b/package.json index 0e60791c..431f85bb 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@jsenv/node-module-import-map", - "version": "13.0.0", + "version": "13.0.0-alpha.2", "description": "Generate importmap for node_modules.", "license": "MIT", "repository": { diff --git a/src/getImportMapFromProjectFiles.js b/src/getImportMapFromProjectFiles.js index f4471f23..d60e6488 100644 --- a/src/getImportMapFromProjectFiles.js +++ b/src/getImportMapFromProjectFiles.js @@ -9,7 +9,7 @@ export const getImportMapFromProjectFiles = async ({ runtime = "browser", moduleFormat = "esm", dev = false, - jsFiles = false, + jsFiles = true, removeUnusedMappings = !dev, magicExtensions, onWarn = (warning, warn) => { diff --git a/src/internal/from-js/getImportMapFromJsFiles.js b/src/internal/from-js/getImportMapFromJsFiles.js index 8c6fb279..29ba3e6f 100644 --- a/src/internal/from-js/getImportMapFromJsFiles.js +++ b/src/internal/from-js/getImportMapFromJsFiles.js @@ -74,6 +74,11 @@ export const getImportMapFromJsFiles = async ({ if (e !== BARE_SPECIFIER_ERROR) { throw e } + if (importer === projectPackageFileUrl) { + // cannot find package main file (package.main is "" for instance) + // we can't discover main file and parse dependencies + return + } gotBareSpecifierError = true fileUrl = resolveUrl(specifier, importer) } diff --git a/src/internal/from-package/getImportMapFromPackageFiles.js b/src/internal/from-package/getImportMapFromPackageFiles.js index 127f4dab..3c3530b1 100644 --- a/src/internal/from-package/getImportMapFromPackageFiles.js +++ b/src/internal/from-package/getImportMapFromPackageFiles.js @@ -34,47 +34,47 @@ export const getImportMapFromPackageFiles = async ({ const imports = {} const scopes = {} - const addTopLevelImportMapping = ({ from, to }) => { - // we could think it's useless to remap from with to - // however it can be used to ensure a weaker remapping - // does not win over this specific file or folder - if (from === to) { - /** - * however remapping '/' to '/' is truly useless - * moreover it would make wrapImportMap create something like - * { - * imports: { - * "/": "/.dist/best/" - * } - * } - * that would append the wrapped folder twice - * */ - if (from === "/") return - } - - imports[from] = to - } - const addScopedImportMapping = ({ scope, from, to }) => { - // when a package says './' maps to './' - // we must add something to say if we are already inside the package - // no need to ensure leading slash are scoped to the package - if (from === "./" && to === scope) { - addScopedImportMapping({ - scope, - from: scope, - to: scope, - }) - const packageName = scope.slice(scope.lastIndexOf("node_modules/") + `node_modules/`.length) - addScopedImportMapping({ - scope, - from: packageName, - to: scope, - }) - } + const addMapping = ({ scope, from, to }) => { + if (scope) { + // when a package says './' maps to './' + // we must add something to say if we are already inside the package + // no need to ensure leading slash are scoped to the package + if (from === "./" && to === scope) { + addMapping({ + scope, + from: scope, + to: scope, + }) + const packageName = scope.slice(scope.lastIndexOf("node_modules/") + `node_modules/`.length) + addMapping({ + scope, + from: packageName, + to: scope, + }) + } - scopes[scope] = { - ...(scopes[scope] || {}), - [from]: to, + scopes[scope] = { + ...(scopes[scope] || {}), + [from]: to, + } + } else { + // we could think it's useless to remap from with to + // however it can be used to ensure a weaker remapping + // does not win over this specific file or folder + if (from === to) { + /** + * however remapping '/' to '/' is truly useless + * moreover it would make wrapImportMap create something like + * { + * imports: { + * "/": "/.dist/best/" + * } + * } + * that would append the wrapped folder twice + * */ + if (from === "/") return + } + imports[from] = to } } @@ -148,7 +148,7 @@ export const getImportMapFromPackageFiles = async ({ if (packageIsRoot) { const { imports = {}, scopes = {} } = importMap Object.keys(imports).forEach((from) => { - addTopLevelImportMapping({ + addMapping({ from, to: imports[from], }) @@ -156,7 +156,7 @@ export const getImportMapFromPackageFiles = async ({ Object.keys(scopes).forEach((scope) => { const scopeMappings = scopes[scope] Object.keys(scopeMappings).forEach((key) => { - addScopedImportMapping({ + addMapping({ scope, from: key, to: scopeMappings[key], @@ -171,7 +171,7 @@ export const getImportMapFromPackageFiles = async ({ Object.keys(imports).forEach((from) => { const to = imports[from] const toMoved = moveMappingValue(to, packageFileUrl, projectDirectoryUrl) - addScopedImportMapping({ + addMapping({ scope, from, to: toMoved, @@ -183,7 +183,7 @@ export const getImportMapFromPackageFiles = async ({ Object.keys(scopeMappings).forEach((key) => { const to = scopeMappings[key] const toMoved = moveMappingValue(to, packageFileUrl, projectDirectoryUrl) - addScopedImportMapping({ + addMapping({ scope: scopeMoved, from: key, to: toMoved, @@ -196,7 +196,7 @@ export const getImportMapFromPackageFiles = async ({ if (packageIsRoot) { Object.keys(mappings).forEach((from) => { const to = mappings[from] - addTopLevelImportMapping({ + addMapping({ from, to, }) @@ -208,12 +208,12 @@ export const getImportMapFromPackageFiles = async ({ // own package mappings available to himself Object.keys(mappings).forEach((from) => { const to = mappings[from] - addScopedImportMapping({ + addMapping({ scope: `./${packageDirectoryRelativeUrl}`, from, to, }) - addTopLevelImportMapping({ from, to }) + addMapping({ from, to }) }) // if importer is root no need to make package mappings available to the importer @@ -224,7 +224,7 @@ export const getImportMapFromPackageFiles = async ({ Object.keys(mappings).forEach((from) => { const to = mappings[from] // own package exports available to himself - addScopedImportMapping({ + addMapping({ scope: `./${packageDirectoryRelativeUrl}`, from, to, @@ -232,7 +232,7 @@ export const getImportMapFromPackageFiles = async ({ // now make package exports available to the importer // here if the importer is himself we could do stuff // we should even handle the case earlier to prevent top level remapping - addScopedImportMapping({ + addMapping({ scope: `./${importerRelativeUrl}`, from, to, @@ -321,16 +321,16 @@ export const getImportMapFromPackageFiles = async ({ const to = `./${mainFileRelativeUrl}` if (importerIsRoot) { - addTopLevelImportMapping({ from, to }) + addMapping({ from, to }) } else { - addScopedImportMapping({ + addMapping({ scope: `./${importerRelativeUrl}`, from, to, }) } if (packageDirectoryUrl !== packageDirectoryUrlExpected) { - addScopedImportMapping({ + addMapping({ scope: `./${importerRelativeUrl}`, from, to, @@ -384,6 +384,9 @@ export const getImportMapFromPackageFiles = async ({ return } + if (dependencyData.syntaxError) { + return + } const { packageFileUrl: dependencyPackageFileUrl, @@ -408,9 +411,7 @@ export const getImportMapFromPackageFiles = async ({ const importerPackageDirectoryUrl = resolveUrl("./", importerPackageFileUrl) - const importerRelativeUrl = importerIsRoot - ? `${urlToBasename(projectDirectoryUrl.slice(0, -1))}/` - : urlToRelativeUrl(importerPackageDirectoryUrl, projectDirectoryUrl) + const importerRelativeUrl = urlToRelativeUrl(importerPackageDirectoryUrl, projectDirectoryUrl) const packageIsRoot = packageFileUrl === projectPackageFileUrl diff --git a/src/internal/from-package/node-module-resolution.js b/src/internal/from-package/node-module-resolution.js index 17b7e0dd..ba9e1274 100644 --- a/src/internal/from-package/node-module-resolution.js +++ b/src/internal/from-package/node-module-resolution.js @@ -19,12 +19,11 @@ export const createFindNodeModulePackage = (packagesManualOverrides) => { return { packageFileUrl: packageFileUrlCandidate, packageJsonObject: packageObjectCandidate, + syntaxError: packageObjectCandidate === PACKAGE_WITH_SYNTAX_ERROR, } }, predicate: ({ packageJsonObject }) => { - return ( - packageJsonObject !== PACKAGE_NOT_FOUND && packageJsonObject !== PACKAGE_WITH_SYNTAX_ERROR - ) + return packageJsonObject !== PACKAGE_NOT_FOUND }, }) } diff --git a/src/internal/from-package/resolvePackageMain.js b/src/internal/from-package/resolvePackageMain.js index 5a3c9c4d..23f9c539 100644 --- a/src/internal/from-package/resolvePackageMain.js +++ b/src/internal/from-package/resolvePackageMain.js @@ -28,7 +28,14 @@ export const resolvePackageMain = ({ }) } - if (packagesExportsPreference.includes("browser") && "browser" in packageJsonObject) { + if ( + packagesExportsPreference.includes("browser") && + "browser" in packageJsonObject && + // when it's an object it means some files + // should be replaced with an other, let's ignore this when we are searching + // for the main file + typeof packageJsonObject.browser === "string" + ) { return resolveMainFile({ warn, packageFileUrl, @@ -134,7 +141,7 @@ const createPackageMainFileNotFoundWarning = ({ }) => { return { code: "PACKAGE_MAIN_FILE_NOT_FOUND", - message: createDetailedMessage(`Cannot find file for "${specifier}"`, { + message: createDetailedMessage(`Cannot find package main file "${specifier}"`, { "imported in": importedIn, "file url tried": fileUrl, ...(urlToExtension(fileUrl) === "" diff --git a/test/getImportMapFromProjectFiles/core/issue-20/issue-20.test.js b/test/getImportMapFromProjectFiles/core/issue-20/issue-20.test.js index 212fa02c..90cc9b39 100644 --- a/test/getImportMapFromProjectFiles/core/issue-20/issue-20.test.js +++ b/test/getImportMapFromProjectFiles/core/issue-20/issue-20.test.js @@ -13,7 +13,6 @@ const importMap = await getImportMapFromProjectFiles({ const expected = { imports: { lume: "./node_modules/lume/lume.js", - root: "./index", }, scopes: { "./node_modules/lume/": { diff --git a/test/getImportMapFromProjectFiles/core/issue-20/root/package.json b/test/getImportMapFromProjectFiles/core/issue-20/root/package.json index 51535ccd..b8dbdd33 100644 --- a/test/getImportMapFromProjectFiles/core/issue-20/root/package.json +++ b/test/getImportMapFromProjectFiles/core/issue-20/root/package.json @@ -1,6 +1,7 @@ { "name": "root", "type": "module", + "main": "", "dependencies": { "lume": "*" } diff --git a/test/getImportMapFromProjectFiles/core/malformed-dependency-package/malformed-dependency-package.test.js b/test/getImportMapFromProjectFiles/core/malformed-dependency-package/malformed-dependency-package.test.js index 881e1d5a..2bb2e209 100644 --- a/test/getImportMapFromProjectFiles/core/malformed-dependency-package/malformed-dependency-package.test.js +++ b/test/getImportMapFromProjectFiles/core/malformed-dependency-package/malformed-dependency-package.test.js @@ -4,16 +4,23 @@ import { getImportMapFromProjectFiles } from "@jsenv/node-module-import-map" const testDirectoryUrl = resolveUrl("./root/", import.meta.url) -const actual = await getImportMapFromProjectFiles({ +const warnings = [] +const importMap = await getImportMapFromProjectFiles({ logLevel: "off", projectDirectoryUrl: testDirectoryUrl, - jsFiles: false, + onWarn: (warning) => { + warnings.push(warning) + }, }) +const actual = { + warnings, + importMap, +} const expected = { - imports: { - root: "./index", + warnings: [], + importMap: { + imports: {}, + scopes: {}, }, - scopes: {}, } -// we could/should also expect a console.warn occurs assert({ actual, expected }) diff --git a/test/getImportMapFromProjectFiles/core/malformed-dependency-package/root/package.json b/test/getImportMapFromProjectFiles/core/malformed-dependency-package/root/package.json index 590673c5..c7a812fc 100644 --- a/test/getImportMapFromProjectFiles/core/malformed-dependency-package/root/package.json +++ b/test/getImportMapFromProjectFiles/core/malformed-dependency-package/root/package.json @@ -1,5 +1,6 @@ { "name": "root", + "main": "", "dependencies": { "malformed": "*" } diff --git a/test/getImportMapFromProjectFiles/core/optional-dependency/optional-dependency.test.js b/test/getImportMapFromProjectFiles/core/optional-dependency/optional-dependency.test.js index ec2b0762..8d3a5a24 100644 --- a/test/getImportMapFromProjectFiles/core/optional-dependency/optional-dependency.test.js +++ b/test/getImportMapFromProjectFiles/core/optional-dependency/optional-dependency.test.js @@ -4,14 +4,24 @@ import { getImportMapFromProjectFiles } from "@jsenv/node-module-import-map" const testDirectoryUrl = resolveUrl("./root/", import.meta.url) -const actual = await getImportMapFromProjectFiles({ +const warnings = [] +const importMap = await getImportMapFromProjectFiles({ projectDirectoryUrl: testDirectoryUrl, - jsFiles: false, + onWarn: (warning) => { + warnings.push(warning) + }, }) +const actual = { + warnings, + importMap, +} const expected = { - imports: { - root: "./index.js", + warnings: [], + importMap: { + imports: { + root: "./index.js", + }, + scopes: {}, }, - scopes: {}, } assert({ actual, expected }) diff --git a/test/getImportMapFromProjectFiles/core/optional-dependency/root/index.js b/test/getImportMapFromProjectFiles/core/optional-dependency/root/index.js new file mode 100644 index 00000000..e69de29b diff --git a/test/getImportMapFromProjectFiles/core/shared-indirect/root/package.json b/test/getImportMapFromProjectFiles/core/shared-indirect/root/package.json index df39c719..b671dd4b 100644 --- a/test/getImportMapFromProjectFiles/core/shared-indirect/root/package.json +++ b/test/getImportMapFromProjectFiles/core/shared-indirect/root/package.json @@ -1,6 +1,7 @@ { "name": "root", "type": "module", + "main": "", "dependencies": { "foo": "*" } diff --git a/test/getImportMapFromProjectFiles/core/shared-indirect/shared-indirect.test.js b/test/getImportMapFromProjectFiles/core/shared-indirect/shared-indirect.test.js index 2b5e279d..ed290558 100644 --- a/test/getImportMapFromProjectFiles/core/shared-indirect/shared-indirect.test.js +++ b/test/getImportMapFromProjectFiles/core/shared-indirect/shared-indirect.test.js @@ -12,7 +12,6 @@ const importMap = await getImportMapFromProjectFiles({ const actual = importMap const expected = { imports: { - root: "./index", foo: "./node_modules/foo/foo.js", }, scopes: { diff --git a/test/getImportMapFromProjectFiles/core/shared/root/package.json b/test/getImportMapFromProjectFiles/core/shared/root/package.json index cccc7ed1..fe3b1db2 100644 --- a/test/getImportMapFromProjectFiles/core/shared/root/package.json +++ b/test/getImportMapFromProjectFiles/core/shared/root/package.json @@ -1,6 +1,7 @@ { "name": "root", "type": "module", + "main": "", "dependencies": { "bar": "*", "foo": "*" diff --git a/test/getImportMapFromProjectFiles/core/shared/shared.test.js b/test/getImportMapFromProjectFiles/core/shared/shared.test.js index 9777d827..bd1e47cb 100644 --- a/test/getImportMapFromProjectFiles/core/shared/shared.test.js +++ b/test/getImportMapFromProjectFiles/core/shared/shared.test.js @@ -13,7 +13,6 @@ const importMap = await getImportMapFromProjectFiles({ const expected = { imports: { "bar/": "./node_modules/bar/", - "root": "./index", "bar": "./node_modules/bar/bar.js", "foo": "./node_modules/foo/foo.js", }, diff --git a/test/getImportMapFromProjectFiles/included-predicate/included-predicate.test.js b/test/getImportMapFromProjectFiles/included-predicate/included-predicate.test.js index d70ddd4b..bc6d941b 100644 --- a/test/getImportMapFromProjectFiles/included-predicate/included-predicate.test.js +++ b/test/getImportMapFromProjectFiles/included-predicate/included-predicate.test.js @@ -10,7 +10,6 @@ const actual = await getImportMapFromProjectFiles({ }) const expected = { imports: { - root: "./index", bar: "./node_modules/bar/index", }, scopes: {}, diff --git a/test/getImportMapFromProjectFiles/included-predicate/root/package.json b/test/getImportMapFromProjectFiles/included-predicate/root/package.json index a6531a3c..a73c1bd9 100644 --- a/test/getImportMapFromProjectFiles/included-predicate/root/package.json +++ b/test/getImportMapFromProjectFiles/included-predicate/root/package.json @@ -1,6 +1,7 @@ { "name": "root", "type": "module", + "main": "", "dependencies": { "foo": "*", "bar": "*" diff --git a/test/getImportMapFromProjectFiles/package-exports-field/exports-pattern-directory/exports-pattern-directory.test.js b/test/getImportMapFromProjectFiles/package-exports-field/exports-pattern-directory/exports-pattern-directory.test.js index 8b530843..c7fcc2ab 100644 --- a/test/getImportMapFromProjectFiles/package-exports-field/exports-pattern-directory/exports-pattern-directory.test.js +++ b/test/getImportMapFromProjectFiles/package-exports-field/exports-pattern-directory/exports-pattern-directory.test.js @@ -10,7 +10,7 @@ const actual = await getImportMapFromProjectFiles({ const expected = { imports: { "foo/": "./node_modules/foo/", - "root": "./index", + "root": "./index.js", "foo": "./node_modules/foo/index", }, scopes: {}, diff --git a/test/getImportMapFromProjectFiles/package-exports-field/exports-pattern-directory/root/index.js b/test/getImportMapFromProjectFiles/package-exports-field/exports-pattern-directory/root/index.js new file mode 100644 index 00000000..e69de29b diff --git a/test/getImportMapFromProjectFiles/package-exports-field/exports-pattern-extensionless/exports-pattern-extensionless.test.js b/test/getImportMapFromProjectFiles/package-exports-field/exports-pattern-extensionless/exports-pattern-extensionless.test.js index 7173db17..7c3b7eba 100644 --- a/test/getImportMapFromProjectFiles/package-exports-field/exports-pattern-extensionless/exports-pattern-extensionless.test.js +++ b/test/getImportMapFromProjectFiles/package-exports-field/exports-pattern-extensionless/exports-pattern-extensionless.test.js @@ -1,17 +1,41 @@ import { assert } from "@jsenv/assert" -import { resolveUrl } from "@jsenv/util" +import { resolveUrl, urlToFileSystemPath } from "@jsenv/util" import { getImportMapFromProjectFiles } from "@jsenv/node-module-import-map" const testDirectoryUrl = resolveUrl("./root/", import.meta.url) -const actual = await getImportMapFromProjectFiles({ +const warnings = [] +const importMap = await getImportMapFromProjectFiles({ projectDirectoryUrl: testDirectoryUrl, + onWarn: (warning) => { + warnings.push(warning) + }, }) +const actual = { + warnings, + importMap, +} const expected = { - imports: { - root: "./index", - foo: "./node_modules/foo/index", + warnings: [ + { + code: "EXPORTS_WILDCARD", + message: `Ignoring export using "*" because it is not supported by importmap. +--- key --- +foo/* +--- value --- +./node_modules/foo/*.js +--- package.json path --- +${urlToFileSystemPath(`${testDirectoryUrl}node_modules/foo/package.json`)} +--- see also --- +https://github.com/WICG/import-maps/issues/232`, + }, + ], + importMap: { + imports: { + root: "./index.js", + foo: "./node_modules/foo/index", + }, + scopes: {}, }, - scopes: {}, } assert({ actual, expected }) diff --git a/test/getImportMapFromProjectFiles/package-exports-field/exports-pattern-extensionless/root/index.js b/test/getImportMapFromProjectFiles/package-exports-field/exports-pattern-extensionless/root/index.js new file mode 100644 index 00000000..e69de29b diff --git a/test/getImportMapFromProjectFiles/package-exports-field/exports-sugar-conditional/root/index b/test/getImportMapFromProjectFiles/package-exports-field/exports-sugar-conditional/root/index new file mode 100644 index 00000000..e69de29b diff --git a/test/getImportMapFromProjectFiles/package-main-field/main-directory/root/index b/test/getImportMapFromProjectFiles/package-main-field/main-directory/root/index new file mode 100644 index 00000000..e69de29b diff --git a/test/getImportMapFromProjectFiles/self-import/self-import-5/root/index b/test/getImportMapFromProjectFiles/self-import/self-import-5/root/index new file mode 100644 index 00000000..e69de29b diff --git a/test/getImportMapFromProjectFiles/self-import/self-import-5/root/node_modules/@jsenv/core/index b/test/getImportMapFromProjectFiles/self-import/self-import-5/root/node_modules/@jsenv/core/index new file mode 100644 index 00000000..e69de29b diff --git a/test/getImportMapFromProjectFiles/self-import/self-import-6/root/index.js b/test/getImportMapFromProjectFiles/self-import/self-import-6/root/index.js new file mode 100644 index 00000000..e69de29b diff --git a/test/getImportMapFromProjectFiles/self-import/self-import-6/self-import-6.test.js b/test/getImportMapFromProjectFiles/self-import/self-import-6/self-import-6.test.js index a2584b54..4abef5a8 100644 --- a/test/getImportMapFromProjectFiles/self-import/self-import-6/self-import-6.test.js +++ b/test/getImportMapFromProjectFiles/self-import/self-import-6/self-import-6.test.js @@ -20,9 +20,6 @@ const expected = { "@jsenv/core/conflict": "./node_modules/@jsenv/core/dep.js", "@jsenv/core": "./node_modules/@jsenv/core/maindep.js", }, - "./root/": { - "@jsenv/core": "./index", - }, }, } assert({ actual, expected }) From da354b71c8fd0b120bb54e902f0530ddb3ac8a66 Mon Sep 17 00:00:00 2001 From: Damien Maillard Date: Fri, 12 Mar 2021 11:55:31 +0100 Subject: [PATCH 30/36] Ensure file content is visited once. Tries as much as possible to help garbage collection --- dist/commonjs/main.cjs | 186 ++++++++++-------- dist/commonjs/main.cjs.map | 33 ++-- package.json | 2 +- .../from-js/getImportMapFromJsFiles.js | 14 +- .../from-js/parseSpecifiersFromFile.js | 4 +- src/internal/memoizeAsyncFunction.js | 29 +-- 6 files changed, 149 insertions(+), 119 deletions(-) diff --git a/dist/commonjs/main.cjs b/dist/commonjs/main.cjs index b025b3e2..428c91cc 100644 --- a/dist/commonjs/main.cjs +++ b/dist/commonjs/main.cjs @@ -9,18 +9,18 @@ var module$1 = require('module'); var cancellation = require('@jsenv/cancellation'); const memoizeAsyncFunctionByUrl = fn => { - const cache = {}; + const map = new WeakMap(); return memoizeAsyncFunction(fn, { getMemoryEntryFromArguments: ([url]) => { return { get: () => { - return cache[url]; + return map.get(url); }, set: promise => { - cache[url] = promise; + map.set(url, promise); }, delete: () => { - delete cache[url]; + map.delete(url); } }; } @@ -69,14 +69,11 @@ const memoizeAsyncFunction = (fn, { return promiseFromMemory; } - let _resolve; - - let _reject; - - const promise = new Promise((resolve, reject) => { - _resolve = resolve; - _reject = reject; - }); + const { + promise, + resolve, + reject + } = createControllablePromise(); memoryEntry.set(promise); let value; let error; @@ -91,15 +88,29 @@ const memoizeAsyncFunction = (fn, { } if (error) { - _reject(error); + reject(error); } else { - _resolve(value); + resolve(value); } return promise; }; }; +const createControllablePromise = () => { + let resolve; + let reject; + const promise = new Promise((res, rej) => { + resolve = res; + reject = rej; + }); + return { + promise, + resolve, + reject + }; +}; + /* global __filename */ const filenameContainsBackSlashes = __filename.indexOf("\\") > -1; const url = filenameContainsBackSlashes ? `file:///${__filename.replace(/\\/g, "/")}` : `file://${__filename}`; @@ -117,7 +128,7 @@ const parseSpecifiersFromFile = async (fileUrl, { allowAwaitOutsideFunction = true, ranges = true, jsx = true, - typescript = true, + typescript = fileUrl.endsWith(".ts") || fileUrl.endsWith(".tsx"), flow = false, ...options } = {}) => { @@ -131,7 +142,7 @@ const parseSpecifiersFromFile = async (fileUrl, { allowAwaitOutsideFunction, ranges, plugins: [// "estree", - "topLevelAwait", "exportDefaultFrom", ...(jsx ? ["jsx"] : []), ...(typescript ? ["typescript"] : []), ...(flow ? ["jsx"] : [])], + "topLevelAwait", "exportDefaultFrom", ...(jsx ? ["jsx"] : []), ...(typescript ? ["typescript"] : []), ...(flow ? ["flow"] : [])], ...options }); const specifiers = {}; @@ -549,6 +560,12 @@ const getImportMapFromJsFiles = async ({ throw e; } + if (importer === projectPackageFileUrl) { + // cannot find package main file (package.main is "" for instance) + // we can't discover main file and parse dependencies + return; + } + gotBareSpecifierError = true; fileUrl = util.resolveUrl(specifier, importer); } @@ -590,23 +607,26 @@ const getImportMapFromJsFiles = async ({ })); } - const fileContent = await readFileContent(fileUrlOnFileSystem); - const specifiers = await parseSpecifiersFromFile(fileUrlOnFileSystem, { + await visitFileContent(fileUrlOnFileSystem); + }; + + const visitFileContent = memoizeAsyncFunctionByUrl(async fileUrl => { + const fileContent = await readFileContent(fileUrl); + const specifiers = await parseSpecifiersFromFile(fileUrl, { fileContent }); await Promise.all(Object.keys(specifiers).map(async specifier => { const specifierInfo = specifiers[specifier]; - await visitFileMemoized(specifier, fileUrlOnFileSystem, { + await visitFileMemoized(specifier, fileUrl, { importedBy: showSource({ - url: fileUrlOnFileSystem, + url: fileUrl, line: specifierInfo.line, column: specifierInfo.column, source: fileContent }) }); })); - }; - + }); const visitFileMemoized = memoizeAsyncFunctionBySpecifierAndImporter(visitFile); const readFileContent = memoizeAsyncFunctionByUrl(fileUrl => { return util.readFile(fileUrl, { @@ -929,7 +949,7 @@ const createPackageMainFileNotFoundWarning = ({ }) => { return { code: "PACKAGE_MAIN_FILE_NOT_FOUND", - message: logger.createDetailedMessage(`Cannot find file for "${specifier}"`, { + message: logger.createDetailedMessage(`Cannot find package main file "${specifier}"`, { "imported in": importedIn, "file url tried": fileUrl, ...(util.urlToExtension(fileUrl) === "" ? { @@ -1373,13 +1393,14 @@ const createFindNodeModulePackage = packagesManualOverrides => { const packageObjectCandidate = await readPackageFileMemoized(packageFileUrlCandidate); return { packageFileUrl: packageFileUrlCandidate, - packageJsonObject: packageObjectCandidate + packageJsonObject: packageObjectCandidate, + syntaxError: packageObjectCandidate === PACKAGE_WITH_SYNTAX_ERROR }; }, predicate: ({ packageJsonObject }) => { - return packageJsonObject !== PACKAGE_NOT_FOUND && packageJsonObject !== PACKAGE_WITH_SYNTAX_ERROR; + return packageJsonObject !== PACKAGE_NOT_FOUND; } }); }; @@ -1426,55 +1447,52 @@ const getImportMapFromPackageFiles = async ({ const imports = {}; const scopes = {}; - const addTopLevelImportMapping = ({ + const addMapping = ({ + scope, from, to }) => { - // we could think it's useless to remap from with to - // however it can be used to ensure a weaker remapping - // does not win over this specific file or folder - if (from === to) { - /** - * however remapping '/' to '/' is truly useless - * moreover it would make wrapImportMap create something like - * { - * imports: { - * "/": "/.dist/best/" - * } - * } - * that would append the wrapped folder twice - * */ - if (from === "/") return; - } + if (scope) { + // when a package says './' maps to './' + // we must add something to say if we are already inside the package + // no need to ensure leading slash are scoped to the package + if (from === "./" && to === scope) { + addMapping({ + scope, + from: scope, + to: scope + }); + const packageName = scope.slice(scope.lastIndexOf("node_modules/") + `node_modules/`.length); + addMapping({ + scope, + from: packageName, + to: scope + }); + } - imports[from] = to; - }; + scopes[scope] = { ...(scopes[scope] || {}), + [from]: to + }; + } else { + // we could think it's useless to remap from with to + // however it can be used to ensure a weaker remapping + // does not win over this specific file or folder + if (from === to) { + /** + * however remapping '/' to '/' is truly useless + * moreover it would make wrapImportMap create something like + * { + * imports: { + * "/": "/.dist/best/" + * } + * } + * that would append the wrapped folder twice + * */ + if (from === "/") return; + } - const addScopedImportMapping = ({ - scope, - from, - to - }) => { - // when a package says './' maps to './' - // we must add something to say if we are already inside the package - // no need to ensure leading slash are scoped to the package - if (from === "./" && to === scope) { - addScopedImportMapping({ - scope, - from: scope, - to: scope - }); - const packageName = scope.slice(scope.lastIndexOf("node_modules/") + `node_modules/`.length); - addScopedImportMapping({ - scope, - from: packageName, - to: scope - }); + imports[from] = to; } - - scopes[scope] = { ...(scopes[scope] || {}), - [from]: to - }; }; const seen = {}; @@ -1554,7 +1572,7 @@ const getImportMapFromPackageFiles = async ({ scopes = {} } = importMap; Object.keys(imports).forEach(from => { - addTopLevelImportMapping({ + addMapping({ from, to: imports[from] }); @@ -1562,7 +1580,7 @@ const getImportMapFromPackageFiles = async ({ Object.keys(scopes).forEach(scope => { const scopeMappings = scopes[scope]; Object.keys(scopeMappings).forEach(key => { - addScopedImportMapping({ + addMapping({ scope, from: key, to: scopeMappings[key] @@ -1580,7 +1598,7 @@ const getImportMapFromPackageFiles = async ({ Object.keys(imports).forEach(from => { const to = imports[from]; const toMoved = moveMappingValue(to, packageFileUrl, projectDirectoryUrl); - addScopedImportMapping({ + addMapping({ scope, from, to: toMoved @@ -1592,7 +1610,7 @@ const getImportMapFromPackageFiles = async ({ Object.keys(scopeMappings).forEach(key => { const to = scopeMappings[key]; const toMoved = moveMappingValue(to, packageFileUrl, projectDirectoryUrl); - addScopedImportMapping({ + addMapping({ scope: scopeMoved, from: key, to: toMoved @@ -1605,7 +1623,7 @@ const getImportMapFromPackageFiles = async ({ if (packageIsRoot) { Object.keys(mappings).forEach(from => { const to = mappings[from]; - addTopLevelImportMapping({ + addMapping({ from, to }); @@ -1617,12 +1635,12 @@ const getImportMapFromPackageFiles = async ({ // own package mappings available to himself Object.keys(mappings).forEach(from => { const to = mappings[from]; - addScopedImportMapping({ + addMapping({ scope: `./${packageDirectoryRelativeUrl}`, from, to }); - addTopLevelImportMapping({ + addMapping({ from, to }); @@ -1635,7 +1653,7 @@ const getImportMapFromPackageFiles = async ({ Object.keys(mappings).forEach(from => { const to = mappings[from]; // own package exports available to himself - addScopedImportMapping({ + addMapping({ scope: `./${packageDirectoryRelativeUrl}`, from, to @@ -1643,7 +1661,7 @@ const getImportMapFromPackageFiles = async ({ // here if the importer is himself we could do stuff // we should even handle the case earlier to prevent top level remapping - addScopedImportMapping({ + addMapping({ scope: `./${importerRelativeUrl}`, from, to @@ -1728,12 +1746,12 @@ const getImportMapFromPackageFiles = async ({ const to = `./${mainFileRelativeUrl}`; if (importerIsRoot) { - addTopLevelImportMapping({ + addMapping({ from, to }); } else { - addScopedImportMapping({ + addMapping({ scope: `./${importerRelativeUrl}`, from, to @@ -1741,7 +1759,7 @@ const getImportMapFromPackageFiles = async ({ } if (packageDirectoryUrl !== packageDirectoryUrlExpected) { - addScopedImportMapping({ + addMapping({ scope: `./${importerRelativeUrl}`, from, to @@ -1795,6 +1813,10 @@ const getImportMapFromPackageFiles = async ({ return; } + if (dependencyData.syntaxError) { + return; + } + const { packageFileUrl: dependencyPackageFileUrl, packageJsonObject: dependencyPackageJsonObject @@ -1821,7 +1843,7 @@ const getImportMapFromPackageFiles = async ({ }) => { const importerIsRoot = importerPackageFileUrl === projectPackageFileUrl; const importerPackageDirectoryUrl = util.resolveUrl("./", importerPackageFileUrl); - const importerRelativeUrl = importerIsRoot ? `${util.urlToBasename(projectDirectoryUrl.slice(0, -1))}/` : util.urlToRelativeUrl(importerPackageDirectoryUrl, projectDirectoryUrl); + const importerRelativeUrl = util.urlToRelativeUrl(importerPackageDirectoryUrl, projectDirectoryUrl); const packageIsRoot = packageFileUrl === projectPackageFileUrl; const packageDirectoryUrl = util.resolveUrl("./", packageFileUrl); const packageDirectoryUrlExpected = `${importerPackageDirectoryUrl}node_modules/${packageName}/`; @@ -2013,7 +2035,7 @@ const getImportMapFromProjectFiles = async ({ runtime = "browser", moduleFormat = "esm", dev = false, - jsFiles = false, + jsFiles = true, removeUnusedMappings = !dev, magicExtensions, onWarn = (warning, warn) => { diff --git a/dist/commonjs/main.cjs.map b/dist/commonjs/main.cjs.map index 114b6217..8fb7f155 100644 --- a/dist/commonjs/main.cjs.map +++ b/dist/commonjs/main.cjs.map @@ -23,22 +23,22 @@ "../../src/writeImportMapFile.js" ], "sourcesContent": [ - "export const memoizeAsyncFunctionByUrl = (fn) => {\n const cache = {}\n return memoizeAsyncFunction(fn, {\n getMemoryEntryFromArguments: ([url]) => {\n return {\n get: () => {\n return cache[url]\n },\n set: (promise) => {\n cache[url] = promise\n },\n delete: () => {\n delete cache[url]\n },\n }\n },\n })\n}\n\nexport const memoizeAsyncFunctionBySpecifierAndImporter = (fn) => {\n const importerCache = {}\n return memoizeAsyncFunction(fn, {\n getMemoryEntryFromArguments: ([specifier, importer]) => {\n return {\n get: () => {\n const specifierCacheForImporter = importerCache[importer]\n return specifierCacheForImporter ? specifierCacheForImporter[specifier] : null\n },\n set: (promise) => {\n const specifierCacheForImporter = importerCache[importer]\n if (specifierCacheForImporter) {\n specifierCacheForImporter[specifier] = promise\n } else {\n importerCache[importer] = {\n [specifier]: promise,\n }\n }\n },\n delete: () => {\n const specifierCacheForImporter = importerCache[importer]\n if (specifierCacheForImporter) {\n delete specifierCacheForImporter[specifier]\n }\n },\n }\n },\n })\n}\n\nconst memoizeAsyncFunction = (fn, { getMemoryEntryFromArguments }) => {\n return async (...args) => {\n const memoryEntry = getMemoryEntryFromArguments(args)\n const promiseFromMemory = memoryEntry.get()\n if (promiseFromMemory) {\n return promiseFromMemory\n }\n let _resolve\n let _reject\n const promise = new Promise((resolve, reject) => {\n _resolve = resolve\n _reject = reject\n })\n memoryEntry.set(promise)\n let value\n let error\n try {\n value = fn(...args)\n error = false\n } catch (e) {\n value = e\n error = true\n memoryEntry.delete()\n }\n if (error) {\n _reject(error)\n } else {\n _resolve(value)\n }\n return promise\n }\n}\n", + "export const memoizeAsyncFunctionByUrl = (fn) => {\n const map = new WeakMap()\n return memoizeAsyncFunction(fn, {\n getMemoryEntryFromArguments: ([url]) => {\n return {\n get: () => {\n return map.get(url)\n },\n set: (promise) => {\n map.set(url, promise)\n },\n delete: () => {\n map.delete(url)\n },\n }\n },\n })\n}\n\nexport const memoizeAsyncFunctionBySpecifierAndImporter = (fn) => {\n const importerCache = {}\n return memoizeAsyncFunction(fn, {\n getMemoryEntryFromArguments: ([specifier, importer]) => {\n return {\n get: () => {\n const specifierCacheForImporter = importerCache[importer]\n return specifierCacheForImporter ? specifierCacheForImporter[specifier] : null\n },\n set: (promise) => {\n const specifierCacheForImporter = importerCache[importer]\n if (specifierCacheForImporter) {\n specifierCacheForImporter[specifier] = promise\n } else {\n importerCache[importer] = {\n [specifier]: promise,\n }\n }\n },\n delete: () => {\n const specifierCacheForImporter = importerCache[importer]\n if (specifierCacheForImporter) {\n delete specifierCacheForImporter[specifier]\n }\n },\n }\n },\n })\n}\n\nconst memoizeAsyncFunction = (fn, { getMemoryEntryFromArguments }) => {\n return async (...args) => {\n const memoryEntry = getMemoryEntryFromArguments(args)\n const promiseFromMemory = memoryEntry.get()\n if (promiseFromMemory) {\n return promiseFromMemory\n }\n const { promise, resolve, reject } = createControllablePromise()\n memoryEntry.set(promise)\n let value\n let error\n try {\n value = fn(...args)\n error = false\n } catch (e) {\n value = e\n error = true\n memoryEntry.delete()\n }\n if (error) {\n reject(error)\n } else {\n resolve(value)\n }\n return promise\n }\n}\n\nconst createControllablePromise = () => {\n let resolve\n let reject\n const promise = new Promise((res, rej) => {\n resolve = res\n reject = rej\n })\n return { promise, resolve, reject }\n}\n", "/* global __filename */\n\nconst filenameContainsBackSlashes = __filename.indexOf(\"\\\\\") > -1\n\nconst url = filenameContainsBackSlashes\n ? `file:///${__filename.replace(/\\\\/g, \"/\")}`\n : `file://${__filename}`\n\nexport default url\n", - "import { createRequire } from \"module\"\nimport { readFile, urlToFileSystemPath } from \"@jsenv/util\"\n\nconst require = createRequire(import.meta.url)\n\nconst parser = require(\"@babel/parser\")\nconst traverse = require(\"@babel/traverse\")\n\nexport const parseSpecifiersFromFile = async (\n fileUrl,\n {\n fileContent,\n sourceType = \"module\",\n allowImportExportEverywhere = true,\n allowAwaitOutsideFunction = true,\n ranges = true,\n jsx = true,\n typescript = true,\n flow = false,\n ...options\n } = {},\n) => {\n fileContent = fileContent === undefined ? await readFile(fileUrl, { as: \"string\" }) : fileContent\n\n const ast = parser.parse(fileContent, {\n sourceType,\n sourceFilename: urlToFileSystemPath(fileUrl),\n allowImportExportEverywhere,\n allowAwaitOutsideFunction,\n ranges,\n plugins: [\n // \"estree\",\n \"topLevelAwait\",\n \"exportDefaultFrom\",\n ...(jsx ? [\"jsx\"] : []),\n ...(typescript ? [\"typescript\"] : []),\n ...(flow ? [\"jsx\"] : []),\n ],\n ...options,\n })\n\n const specifiers = {}\n\n const addSpecifier = ({ path, type }) => {\n const specifier = path.node.value\n specifiers[specifier] = {\n line: path.node.loc.start.line,\n column: path.node.loc.start.column,\n type,\n }\n }\n\n traverse.default(ast, {\n // ImportExpression: (path) => {\n // if (path.node.arguments[0].type !== \"StringLiteral\") {\n // // Non-string argument, probably a variable or expression, e.g.\n // // import(moduleId)\n // // import('./' + moduleName)\n // return\n // }\n // addSpecifier(path.get(\"arguments\")[0])\n // },\n CallExpression: (path) => {\n if (path.node.callee.type !== \"Import\") {\n // Some other function call, not import();\n return\n }\n if (path.node.arguments[0].type !== \"StringLiteral\") {\n // Non-string argument, probably a variable or expression, e.g.\n // import(moduleId)\n // import('./' + moduleName)\n return\n }\n addSpecifier({\n path: path.get(\"arguments\")[0],\n type: \"import-dynamic\",\n })\n },\n ExportAllDeclaration: (path) => {\n addSpecifier({\n path: path.get(\"source\"),\n type: \"export-all\",\n })\n },\n ExportNamedDeclaration: (path) => {\n if (!path.node.source) {\n // This export has no \"source\", so it's probably\n // a local variable or function, e.g.\n // export { varName }\n // export const constName = ...\n // export function funcName() {}\n return\n }\n addSpecifier({\n path: path.get(\"source\"),\n type: \"export-named\",\n })\n },\n ImportDeclaration: (path) => {\n addSpecifier({\n path: path.get(\"source\"),\n type: \"import-static\",\n })\n },\n })\n\n return specifiers\n}\n", + "import { createRequire } from \"module\"\nimport { readFile, urlToFileSystemPath } from \"@jsenv/util\"\n\nconst require = createRequire(import.meta.url)\n\nconst parser = require(\"@babel/parser\")\nconst traverse = require(\"@babel/traverse\")\n\nexport const parseSpecifiersFromFile = async (\n fileUrl,\n {\n fileContent,\n sourceType = \"module\",\n allowImportExportEverywhere = true,\n allowAwaitOutsideFunction = true,\n ranges = true,\n jsx = true,\n typescript = fileUrl.endsWith(\".ts\") || fileUrl.endsWith(\".tsx\"),\n flow = false,\n ...options\n } = {},\n) => {\n fileContent = fileContent === undefined ? await readFile(fileUrl, { as: \"string\" }) : fileContent\n\n const ast = parser.parse(fileContent, {\n sourceType,\n sourceFilename: urlToFileSystemPath(fileUrl),\n allowImportExportEverywhere,\n allowAwaitOutsideFunction,\n ranges,\n plugins: [\n // \"estree\",\n \"topLevelAwait\",\n \"exportDefaultFrom\",\n ...(jsx ? [\"jsx\"] : []),\n ...(typescript ? [\"typescript\"] : []),\n ...(flow ? [\"flow\"] : []),\n ],\n ...options,\n })\n\n const specifiers = {}\n\n const addSpecifier = ({ path, type }) => {\n const specifier = path.node.value\n specifiers[specifier] = {\n line: path.node.loc.start.line,\n column: path.node.loc.start.column,\n type,\n }\n }\n\n traverse.default(ast, {\n // ImportExpression: (path) => {\n // if (path.node.arguments[0].type !== \"StringLiteral\") {\n // // Non-string argument, probably a variable or expression, e.g.\n // // import(moduleId)\n // // import('./' + moduleName)\n // return\n // }\n // addSpecifier(path.get(\"arguments\")[0])\n // },\n CallExpression: (path) => {\n if (path.node.callee.type !== \"Import\") {\n // Some other function call, not import();\n return\n }\n if (path.node.arguments[0].type !== \"StringLiteral\") {\n // Non-string argument, probably a variable or expression, e.g.\n // import(moduleId)\n // import('./' + moduleName)\n return\n }\n addSpecifier({\n path: path.get(\"arguments\")[0],\n type: \"import-dynamic\",\n })\n },\n ExportAllDeclaration: (path) => {\n addSpecifier({\n path: path.get(\"source\"),\n type: \"export-all\",\n })\n },\n ExportNamedDeclaration: (path) => {\n if (!path.node.source) {\n // This export has no \"source\", so it's probably\n // a local variable or function, e.g.\n // export { varName }\n // export const constName = ...\n // export function funcName() {}\n return\n }\n addSpecifier({\n path: path.get(\"source\"),\n type: \"export-named\",\n })\n },\n ImportDeclaration: (path) => {\n addSpecifier({\n path: path.get(\"source\"),\n type: \"import-static\",\n })\n },\n })\n\n return specifiers\n}\n", "// https://github.com/postcss/postcss/blob/fd30d3df5abc0954a0ec642a3cdc644ab2aacf9c/lib/css-syntax-error.js#L43\n// https://github.com/postcss/postcss/blob/fd30d3df5abc0954a0ec642a3cdc644ab2aacf9c/lib/terminal-highlight.js#L50\n// https://github.com/babel/babel/blob/eea156b2cb8deecfcf82d52aa1b71ba4995c7d68/packages/babel-code-frame/src/index.js#L1\n\nexport const showSource = ({ url, line, column, source }) => {\n let message = \"\"\n\n message += typeof url === \"undefined\" ? \"Anonymous\" : url\n if (typeof line !== \"number\") {\n return message\n }\n\n message += `:${line}`\n if (typeof column === \"number\") {\n message += `:${column}`\n }\n\n if (!source) {\n return message\n }\n\n return `${message}\n${showSourceLocation(source, {\n line,\n column,\n})}`\n}\n\nconst red = \"\\x1b[31m\"\nconst grey = \"\\x1b[39m\"\nconst ansiResetSequence = \"\\x1b[0m\"\n\nconst showSourceLocation = (\n source,\n {\n line,\n column,\n numberOfSurroundingLinesToShow = 1,\n lineMaxLength = 120,\n color = false,\n markColor = red,\n asideColor = grey,\n colorMark = (string) => `${markColor}${string}${ansiResetSequence}`,\n colorAside = (string) => `${asideColor}${string}${ansiResetSequence}`,\n },\n) => {\n const mark = color ? colorMark : (string) => string\n const aside = color ? colorAside : (string) => string\n\n const lines = source.split(/\\r?\\n/)\n let lineRange = {\n start: line - 1,\n end: line,\n }\n lineRange = moveLineRangeUp(lineRange, numberOfSurroundingLinesToShow)\n lineRange = moveLineRangeDown(lineRange, numberOfSurroundingLinesToShow)\n lineRange = lineRangeWithinLines(lineRange, lines)\n const linesToShow = lines.slice(lineRange.start, lineRange.end)\n const endLineNumber = lineRange.end\n const lineNumberMaxWidth = String(endLineNumber).length\n\n const columnRange = {}\n if (column === undefined) {\n columnRange.start = 0\n columnRange.end = lineMaxLength\n } else if (column > lineMaxLength) {\n columnRange.start = column - Math.floor(lineMaxLength / 2)\n columnRange.end = column + Math.ceil(lineMaxLength / 2)\n } else {\n columnRange.start = 0\n columnRange.end = lineMaxLength\n }\n\n return linesToShow.map((lineSource, index) => {\n const lineNumber = lineRange.start + index + 1\n const isMainLine = lineNumber === line\n const lineSourceTruncated = applyColumnRange(columnRange, lineSource)\n const lineNumberWidth = String(lineNumber).length\n // ensure if line moves from 7,8,9 to 10 the display is still great\n const lineNumberRightSpacing = \" \".repeat(lineNumberMaxWidth - lineNumberWidth)\n const asideSource = `${lineNumber}${lineNumberRightSpacing} |`\n const lineFormatted = `${aside(asideSource)} ${lineSourceTruncated}`\n if (isMainLine) {\n if (column === undefined) {\n return `${mark(\">\")} ${lineFormatted}`\n }\n const lineSourceUntilColumn = lineSourceTruncated.slice(0, column - columnRange.start)\n const spacing = stringToSpaces(lineSourceUntilColumn)\n const mainLineFormatted = `${mark(\">\")} ${lineFormatted}\n ${\" \".repeat(lineNumberWidth)} ${aside(\"|\")}${spacing}${mark(\"^\")}`\n return mainLineFormatted\n }\n return ` ${lineFormatted}`\n }).join(`\n`)\n}\n\nconst applyColumnRange = ({ start, end }, line) => {\n if (typeof start !== \"number\") {\n throw new TypeError(`start must be a number, received ${start}`)\n }\n if (typeof end !== \"number\") {\n throw new TypeError(`end must be a number, received ${end}`)\n }\n if (end < start) {\n throw new Error(`end must be greater than start, but ${end} is smaller than ${start}`)\n }\n\n const prefix = \"…\"\n const suffix = \"…\"\n const lastIndex = line.length\n\n if (line.length === 0) {\n // don't show any ellipsis if the line is empty\n // because it's not truncated in that case\n return \"\"\n }\n\n const startTruncated = start > 0\n const endTruncated = lastIndex > end\n\n let from = startTruncated ? start + prefix.length : start\n let to = endTruncated ? end - suffix.length : end\n if (to > lastIndex) to = lastIndex\n\n if (start >= lastIndex || from === to) {\n return \"\"\n }\n\n let result = \"\"\n while (from < to) {\n result += line[from]\n from++\n }\n\n if (result.length === 0) {\n return \"\"\n }\n if (startTruncated && endTruncated) {\n return `${prefix}${result}${suffix}`\n }\n if (startTruncated) {\n return `${prefix}${result}`\n }\n if (endTruncated) {\n return `${result}${suffix}`\n }\n return result\n}\n\nconst stringToSpaces = (string) => string.replace(/[^\\t]/g, \" \")\n\n// const getLineRangeLength = ({ start, end }) => end - start\n\nconst moveLineRangeUp = ({ start, end }, number) => {\n return {\n start: start - number,\n end,\n }\n}\n\nconst moveLineRangeDown = ({ start, end }, number) => {\n return {\n start,\n end: end + number,\n }\n}\n\nconst lineRangeWithinLines = ({ start, end }, lines) => {\n return {\n start: start < 0 ? 0 : start,\n end: end > lines.length ? lines.length : end,\n }\n}\n", "import { resolveUrl, readFileSystemNodeStat, urlToFilename, urlToExtension } from \"@jsenv/util\"\nimport { firstOperationMatching } from \"@jsenv/cancellation\"\n\nexport const resolveFile = async (fileUrl, { magicExtensions }) => {\n const fileStat = await readFileSystemNodeStat(fileUrl, {\n nullIfNotFound: true,\n })\n\n // file found\n if (fileStat && fileStat.isFile()) {\n return fileUrl\n }\n\n // directory found\n if (fileStat && fileStat.isDirectory()) {\n const indexFileSuffix = fileUrl.endsWith(\"/\") ? \"index\" : \"/index\"\n const indexFileUrl = `${fileUrl}${indexFileSuffix}`\n const extensionLeadingToAFile = await findExtensionLeadingToFile(indexFileUrl, magicExtensions)\n if (extensionLeadingToAFile === null) {\n return null\n }\n return `${indexFileUrl}${extensionLeadingToAFile}`\n }\n\n // file not found and it has an extension\n const extension = urlToExtension(fileUrl)\n if (extension !== \"\") {\n return null\n }\n\n const extensionLeadingToAFile = await findExtensionLeadingToFile(fileUrl, magicExtensions)\n // magic extension not found\n if (extensionLeadingToAFile === null) {\n return null\n }\n\n // magic extension worked\n return `${fileUrl}${extensionLeadingToAFile}`\n}\n\nconst findExtensionLeadingToFile = async (fileUrl, magicExtensions) => {\n const urlDirectoryUrl = resolveUrl(\"./\", fileUrl)\n const urlFilename = urlToFilename(fileUrl)\n const extensionLeadingToFile = await firstOperationMatching({\n array: magicExtensions,\n start: async (extensionCandidate) => {\n const urlCandidate = `${urlDirectoryUrl}${urlFilename}${extensionCandidate}`\n const stats = await readFileSystemNodeStat(urlCandidate, { nullIfNotFound: true })\n return stats && stats.isFile() ? extensionCandidate : null\n },\n predicate: (extension) => Boolean(extension),\n })\n return extensionLeadingToFile || null\n}\n", - "import { createDetailedMessage } from \"@jsenv/logger\"\nimport { resolveUrl, readFile, urlToExtension, urlToRelativeUrl } from \"@jsenv/util\"\nimport { normalizeImportMap, resolveImport } from \"@jsenv/import-map\"\nimport {\n memoizeAsyncFunctionByUrl,\n memoizeAsyncFunctionBySpecifierAndImporter,\n} from \"../memoizeAsyncFunction.js\"\nimport { parseSpecifiersFromFile } from \"./parseSpecifiersFromFile.js\"\nimport { showSource } from \"./showSource.js\"\nimport { resolveFile } from \"../resolveFile.js\"\n\nconst BARE_SPECIFIER_ERROR = {}\n\nexport const getImportMapFromJsFiles = async ({\n warn,\n importMap,\n projectDirectoryUrl,\n removeUnusedMappings,\n magicExtensions = [\".js\", \".jsx\", \".ts\", \".tsx\", \".node\", \".json\"],\n}) => {\n const projectPackageFileUrl = resolveUrl(\"./package.json\", projectDirectoryUrl)\n\n const imports = {}\n const scopes = {}\n const addMapping = ({ scope, from, to }) => {\n if (scope) {\n scopes[scope] = {\n ...(scopes[scope] || {}),\n [from]: to,\n }\n } else {\n imports[from] = to\n }\n }\n\n const topLevelMappingsUsed = []\n const scopedMappingsUsed = {}\n const markMappingAsUsed = ({ scope, from, to }) => {\n if (scope) {\n if (scope in scopedMappingsUsed) {\n scopedMappingsUsed[scope].push({ from, to })\n } else {\n scopedMappingsUsed[scope] = [{ from, to }]\n }\n } else {\n topLevelMappingsUsed.push({ from, to })\n }\n }\n const importMapNormalized = normalizeImportMap(importMap, projectDirectoryUrl)\n const trackAndResolveImport = (specifier, importer) => {\n return resolveImport({\n specifier,\n importer,\n importMap: importMapNormalized,\n defaultExtension: false,\n onImportMapping: ({ scope, from }) => {\n markMappingAsUsed({\n scope,\n from,\n to: scope ? importMap.scopes[scope][from] : importMap.imports[from],\n })\n },\n createBareSpecifierError: () => BARE_SPECIFIER_ERROR,\n })\n }\n\n const visitFile = async (specifier, importer, { importedBy }) => {\n let fileUrl\n let gotBareSpecifierError = false\n\n try {\n fileUrl = trackAndResolveImport(specifier, importer)\n } catch (e) {\n if (e !== BARE_SPECIFIER_ERROR) {\n throw e\n }\n gotBareSpecifierError = true\n fileUrl = resolveUrl(specifier, importer)\n }\n\n const fileUrlOnFileSystem = await resolveFile(fileUrl, {\n magicExtensions: magicExtensionWithImporterExtension(magicExtensions, importer),\n })\n\n if (!fileUrlOnFileSystem) {\n warn(\n createFileNotFoundWarning({\n specifier,\n importedBy,\n fileUrl,\n magicExtensions,\n }),\n )\n return\n }\n\n const needsAutoMapping = fileUrlOnFileSystem !== fileUrl || gotBareSpecifierError\n if (needsAutoMapping) {\n const packageDirectoryUrl = packageDirectoryUrlFromUrl(fileUrl, projectDirectoryUrl)\n const packageFileUrl = resolveUrl(\"package.json\", packageDirectoryUrl)\n const autoMapping = {\n scope:\n packageFileUrl === projectPackageFileUrl\n ? undefined\n : `./${urlToRelativeUrl(packageDirectoryUrl, projectDirectoryUrl)}`,\n from: specifier,\n to: `./${urlToRelativeUrl(fileUrlOnFileSystem, projectDirectoryUrl)}`,\n }\n addMapping(autoMapping)\n markMappingAsUsed(autoMapping)\n warn(\n formatAutoMappingSpecifierWarning({\n specifier,\n importedBy,\n autoMapping,\n closestPackageDirectoryUrl: packageDirectoryUrl,\n closestPackageObject: await readFile(packageFileUrl, { as: \"json\" }),\n }),\n )\n }\n\n const fileContent = await readFileContent(fileUrlOnFileSystem)\n const specifiers = await parseSpecifiersFromFile(fileUrlOnFileSystem, { fileContent })\n\n await Promise.all(\n Object.keys(specifiers).map(async (specifier) => {\n const specifierInfo = specifiers[specifier]\n await visitFileMemoized(specifier, fileUrlOnFileSystem, {\n importedBy: showSource({\n url: fileUrlOnFileSystem,\n line: specifierInfo.line,\n column: specifierInfo.column,\n source: fileContent,\n }),\n })\n }),\n )\n }\n const visitFileMemoized = memoizeAsyncFunctionBySpecifierAndImporter(visitFile)\n\n const readFileContent = memoizeAsyncFunctionByUrl((fileUrl) => {\n return readFile(fileUrl, { as: \"string\" })\n })\n\n const projectPackageObject = await readFile(projectPackageFileUrl, { as: \"json\" })\n await visitFileMemoized(projectPackageObject.name, projectPackageFileUrl, {\n importedBy: projectPackageObject.exports\n ? `${projectPackageFileUrl}#exports`\n : `${projectPackageFileUrl}`,\n })\n\n if (removeUnusedMappings) {\n const importsUsed = {}\n topLevelMappingsUsed.forEach(({ from, to }) => {\n importsUsed[from] = to\n })\n const scopesUsed = {}\n Object.keys(scopedMappingsUsed).forEach((scope) => {\n const mappingsUsed = scopedMappingsUsed[scope]\n const scopedMappings = {}\n mappingsUsed.forEach(({ from, to }) => {\n scopedMappings[from] = to\n })\n scopesUsed[scope] = scopedMappings\n })\n return {\n imports: importsUsed,\n scopes: scopesUsed,\n }\n }\n\n return { imports, scopes }\n}\n\nconst packageDirectoryUrlFromUrl = (url, projectDirectoryUrl) => {\n const relativeUrl = urlToRelativeUrl(url, projectDirectoryUrl)\n\n const lastNodeModulesDirectoryStartIndex = relativeUrl.lastIndexOf(\"node_modules/\")\n if (lastNodeModulesDirectoryStartIndex === -1) {\n return projectDirectoryUrl\n }\n\n const lastNodeModulesDirectoryEndIndex =\n lastNodeModulesDirectoryStartIndex + `node_modules/`.length\n\n const beforeNodeModulesLastDirectory = relativeUrl.slice(0, lastNodeModulesDirectoryEndIndex)\n const afterLastNodeModulesDirectory = relativeUrl.slice(lastNodeModulesDirectoryEndIndex)\n const remainingDirectories = afterLastNodeModulesDirectory.split(\"/\")\n\n if (afterLastNodeModulesDirectory[0] === \"@\") {\n // scoped package\n return `${projectDirectoryUrl}${beforeNodeModulesLastDirectory}${remainingDirectories\n .slice(0, 2)\n .join(\"/\")}`\n }\n return `${projectDirectoryUrl}${beforeNodeModulesLastDirectory}${remainingDirectories[0]}/`\n}\n\nconst magicExtensionWithImporterExtension = (magicExtensions, importer) => {\n const importerExtension = urlToExtension(importer)\n const magicExtensionsWithoutImporterExtension = magicExtensions.filter(\n (ext) => ext !== importerExtension,\n )\n return [importerExtension, ...magicExtensionsWithoutImporterExtension]\n}\n\nconst createFileNotFoundWarning = ({ specifier, importedBy, fileUrl, magicExtensions }) => {\n return {\n code: \"FILE_NOT_FOUND\",\n message: createDetailedMessage(`Cannot find file for \"${specifier}\"`, {\n \"specifier origin\": importedBy,\n \"file url tried\": fileUrl,\n ...(urlToExtension(fileUrl) === \"\"\n ? { [\"extensions tried\"]: magicExtensions.join(`, `) }\n : {}),\n }),\n }\n}\n\nconst formatAutoMappingSpecifierWarning = ({\n importedBy,\n autoMapping,\n closestPackageDirectoryUrl,\n closestPackageObject,\n}) => {\n return {\n code: \"AUTO_MAPPING\",\n message: createDetailedMessage(`Auto mapping ${autoMapping.from} to ${autoMapping.to}.`, {\n \"specifier origin\": importedBy,\n \"suggestion\": decideAutoMappingSuggestion({\n autoMapping,\n closestPackageDirectoryUrl,\n closestPackageObject,\n }),\n }),\n }\n}\n\nconst decideAutoMappingSuggestion = ({\n autoMapping,\n closestPackageDirectoryUrl,\n closestPackageObject,\n}) => {\n if (typeof closestPackageObject.importmap === \"string\") {\n const packageImportmapFileUrl = resolveUrl(\n closestPackageObject.importmap,\n closestPackageDirectoryUrl,\n )\n\n return `To get rid of this warning, add an explicit mapping into importmap file.\n${mappingToImportmapString(autoMapping)}\ninto ${packageImportmapFileUrl}.`\n }\n\n return `To get rid of this warning, add an explicit mapping into package.json.\n${mappingToExportsFieldString(autoMapping)}\ninto ${closestPackageDirectoryUrl}package.json.`\n}\n\nconst mappingToImportmapString = ({ scope, from, to }) => {\n if (scope) {\n return JSON.stringify(\n {\n scopes: {\n [scope]: {\n [from]: to,\n },\n },\n },\n null,\n \" \",\n )\n }\n\n return JSON.stringify(\n {\n imports: {\n [from]: to,\n },\n },\n null,\n \" \",\n )\n}\n\nconst mappingToExportsFieldString = ({ scope, from, to }) => {\n if (scope) {\n const scopeUrl = resolveUrl(scope, \"file://\")\n const toUrl = resolveUrl(to, \"file://\")\n to = `./${urlToRelativeUrl(toUrl, scopeUrl)}`\n }\n\n return JSON.stringify(\n {\n exports: {\n [from]: to,\n },\n },\n null,\n \" \",\n )\n}\n", + "import { createDetailedMessage } from \"@jsenv/logger\"\nimport { resolveUrl, readFile, urlToExtension, urlToRelativeUrl } from \"@jsenv/util\"\nimport { normalizeImportMap, resolveImport } from \"@jsenv/import-map\"\nimport {\n memoizeAsyncFunctionByUrl,\n memoizeAsyncFunctionBySpecifierAndImporter,\n} from \"../memoizeAsyncFunction.js\"\nimport { parseSpecifiersFromFile } from \"./parseSpecifiersFromFile.js\"\nimport { showSource } from \"./showSource.js\"\nimport { resolveFile } from \"../resolveFile.js\"\n\nconst BARE_SPECIFIER_ERROR = {}\n\nexport const getImportMapFromJsFiles = async ({\n warn,\n importMap,\n projectDirectoryUrl,\n removeUnusedMappings,\n magicExtensions = [\".js\", \".jsx\", \".ts\", \".tsx\", \".node\", \".json\"],\n}) => {\n const projectPackageFileUrl = resolveUrl(\"./package.json\", projectDirectoryUrl)\n\n const imports = {}\n const scopes = {}\n const addMapping = ({ scope, from, to }) => {\n if (scope) {\n scopes[scope] = {\n ...(scopes[scope] || {}),\n [from]: to,\n }\n } else {\n imports[from] = to\n }\n }\n\n const topLevelMappingsUsed = []\n const scopedMappingsUsed = {}\n const markMappingAsUsed = ({ scope, from, to }) => {\n if (scope) {\n if (scope in scopedMappingsUsed) {\n scopedMappingsUsed[scope].push({ from, to })\n } else {\n scopedMappingsUsed[scope] = [{ from, to }]\n }\n } else {\n topLevelMappingsUsed.push({ from, to })\n }\n }\n const importMapNormalized = normalizeImportMap(importMap, projectDirectoryUrl)\n const trackAndResolveImport = (specifier, importer) => {\n return resolveImport({\n specifier,\n importer,\n importMap: importMapNormalized,\n defaultExtension: false,\n onImportMapping: ({ scope, from }) => {\n markMappingAsUsed({\n scope,\n from,\n to: scope ? importMap.scopes[scope][from] : importMap.imports[from],\n })\n },\n createBareSpecifierError: () => BARE_SPECIFIER_ERROR,\n })\n }\n\n const visitFile = async (specifier, importer, { importedBy }) => {\n let fileUrl\n let gotBareSpecifierError = false\n\n try {\n fileUrl = trackAndResolveImport(specifier, importer)\n } catch (e) {\n if (e !== BARE_SPECIFIER_ERROR) {\n throw e\n }\n if (importer === projectPackageFileUrl) {\n // cannot find package main file (package.main is \"\" for instance)\n // we can't discover main file and parse dependencies\n return\n }\n gotBareSpecifierError = true\n fileUrl = resolveUrl(specifier, importer)\n }\n\n const fileUrlOnFileSystem = await resolveFile(fileUrl, {\n magicExtensions: magicExtensionWithImporterExtension(magicExtensions, importer),\n })\n\n if (!fileUrlOnFileSystem) {\n warn(\n createFileNotFoundWarning({\n specifier,\n importedBy,\n fileUrl,\n magicExtensions,\n }),\n )\n return\n }\n\n const needsAutoMapping = fileUrlOnFileSystem !== fileUrl || gotBareSpecifierError\n if (needsAutoMapping) {\n const packageDirectoryUrl = packageDirectoryUrlFromUrl(fileUrl, projectDirectoryUrl)\n const packageFileUrl = resolveUrl(\"package.json\", packageDirectoryUrl)\n const autoMapping = {\n scope:\n packageFileUrl === projectPackageFileUrl\n ? undefined\n : `./${urlToRelativeUrl(packageDirectoryUrl, projectDirectoryUrl)}`,\n from: specifier,\n to: `./${urlToRelativeUrl(fileUrlOnFileSystem, projectDirectoryUrl)}`,\n }\n addMapping(autoMapping)\n markMappingAsUsed(autoMapping)\n warn(\n formatAutoMappingSpecifierWarning({\n specifier,\n importedBy,\n autoMapping,\n closestPackageDirectoryUrl: packageDirectoryUrl,\n closestPackageObject: await readFile(packageFileUrl, { as: \"json\" }),\n }),\n )\n }\n\n await visitFileContent(fileUrlOnFileSystem)\n }\n\n const visitFileContent = memoizeAsyncFunctionByUrl(async (fileUrl) => {\n const fileContent = await readFileContent(fileUrl)\n const specifiers = await parseSpecifiersFromFile(fileUrl, { fileContent })\n\n await Promise.all(\n Object.keys(specifiers).map(async (specifier) => {\n const specifierInfo = specifiers[specifier]\n await visitFileMemoized(specifier, fileUrl, {\n importedBy: showSource({\n url: fileUrl,\n line: specifierInfo.line,\n column: specifierInfo.column,\n source: fileContent,\n }),\n })\n }),\n )\n })\n const visitFileMemoized = memoizeAsyncFunctionBySpecifierAndImporter(visitFile)\n\n const readFileContent = memoizeAsyncFunctionByUrl((fileUrl) => {\n return readFile(fileUrl, { as: \"string\" })\n })\n\n const projectPackageObject = await readFile(projectPackageFileUrl, { as: \"json\" })\n await visitFileMemoized(projectPackageObject.name, projectPackageFileUrl, {\n importedBy: projectPackageObject.exports\n ? `${projectPackageFileUrl}#exports`\n : `${projectPackageFileUrl}`,\n })\n\n if (removeUnusedMappings) {\n const importsUsed = {}\n topLevelMappingsUsed.forEach(({ from, to }) => {\n importsUsed[from] = to\n })\n const scopesUsed = {}\n Object.keys(scopedMappingsUsed).forEach((scope) => {\n const mappingsUsed = scopedMappingsUsed[scope]\n const scopedMappings = {}\n mappingsUsed.forEach(({ from, to }) => {\n scopedMappings[from] = to\n })\n scopesUsed[scope] = scopedMappings\n })\n return {\n imports: importsUsed,\n scopes: scopesUsed,\n }\n }\n\n return { imports, scopes }\n}\n\nconst packageDirectoryUrlFromUrl = (url, projectDirectoryUrl) => {\n const relativeUrl = urlToRelativeUrl(url, projectDirectoryUrl)\n\n const lastNodeModulesDirectoryStartIndex = relativeUrl.lastIndexOf(\"node_modules/\")\n if (lastNodeModulesDirectoryStartIndex === -1) {\n return projectDirectoryUrl\n }\n\n const lastNodeModulesDirectoryEndIndex =\n lastNodeModulesDirectoryStartIndex + `node_modules/`.length\n\n const beforeNodeModulesLastDirectory = relativeUrl.slice(0, lastNodeModulesDirectoryEndIndex)\n const afterLastNodeModulesDirectory = relativeUrl.slice(lastNodeModulesDirectoryEndIndex)\n const remainingDirectories = afterLastNodeModulesDirectory.split(\"/\")\n\n if (afterLastNodeModulesDirectory[0] === \"@\") {\n // scoped package\n return `${projectDirectoryUrl}${beforeNodeModulesLastDirectory}${remainingDirectories\n .slice(0, 2)\n .join(\"/\")}`\n }\n return `${projectDirectoryUrl}${beforeNodeModulesLastDirectory}${remainingDirectories[0]}/`\n}\n\nconst magicExtensionWithImporterExtension = (magicExtensions, importer) => {\n const importerExtension = urlToExtension(importer)\n const magicExtensionsWithoutImporterExtension = magicExtensions.filter(\n (ext) => ext !== importerExtension,\n )\n return [importerExtension, ...magicExtensionsWithoutImporterExtension]\n}\n\nconst createFileNotFoundWarning = ({ specifier, importedBy, fileUrl, magicExtensions }) => {\n return {\n code: \"FILE_NOT_FOUND\",\n message: createDetailedMessage(`Cannot find file for \"${specifier}\"`, {\n \"specifier origin\": importedBy,\n \"file url tried\": fileUrl,\n ...(urlToExtension(fileUrl) === \"\"\n ? { [\"extensions tried\"]: magicExtensions.join(`, `) }\n : {}),\n }),\n }\n}\n\nconst formatAutoMappingSpecifierWarning = ({\n importedBy,\n autoMapping,\n closestPackageDirectoryUrl,\n closestPackageObject,\n}) => {\n return {\n code: \"AUTO_MAPPING\",\n message: createDetailedMessage(`Auto mapping ${autoMapping.from} to ${autoMapping.to}.`, {\n \"specifier origin\": importedBy,\n \"suggestion\": decideAutoMappingSuggestion({\n autoMapping,\n closestPackageDirectoryUrl,\n closestPackageObject,\n }),\n }),\n }\n}\n\nconst decideAutoMappingSuggestion = ({\n autoMapping,\n closestPackageDirectoryUrl,\n closestPackageObject,\n}) => {\n if (typeof closestPackageObject.importmap === \"string\") {\n const packageImportmapFileUrl = resolveUrl(\n closestPackageObject.importmap,\n closestPackageDirectoryUrl,\n )\n\n return `To get rid of this warning, add an explicit mapping into importmap file.\n${mappingToImportmapString(autoMapping)}\ninto ${packageImportmapFileUrl}.`\n }\n\n return `To get rid of this warning, add an explicit mapping into package.json.\n${mappingToExportsFieldString(autoMapping)}\ninto ${closestPackageDirectoryUrl}package.json.`\n}\n\nconst mappingToImportmapString = ({ scope, from, to }) => {\n if (scope) {\n return JSON.stringify(\n {\n scopes: {\n [scope]: {\n [from]: to,\n },\n },\n },\n null,\n \" \",\n )\n }\n\n return JSON.stringify(\n {\n imports: {\n [from]: to,\n },\n },\n null,\n \" \",\n )\n}\n\nconst mappingToExportsFieldString = ({ scope, from, to }) => {\n if (scope) {\n const scopeUrl = resolveUrl(scope, \"file://\")\n const toUrl = resolveUrl(to, \"file://\")\n to = `./${urlToRelativeUrl(toUrl, scopeUrl)}`\n }\n\n return JSON.stringify(\n {\n exports: {\n [from]: to,\n },\n },\n null,\n \" \",\n )\n}\n", "export const optimizeImportMap = ({ imports, scopes }) => {\n // remove useless duplicates (scoped key+value already defined on imports)\n const scopesOptimized = {}\n Object.keys(scopes).forEach((scope) => {\n const scopeMappings = scopes[scope]\n const scopeMappingsOptimized = {}\n Object.keys(scopeMappings).forEach((mappingKey) => {\n const topLevelMappingValue = imports[mappingKey]\n const mappingValue = scopeMappings[mappingKey]\n if (!topLevelMappingValue || topLevelMappingValue !== mappingValue) {\n scopeMappingsOptimized[mappingKey] = mappingValue\n }\n })\n if (Object.keys(scopeMappingsOptimized).length > 0) {\n scopesOptimized[scope] = scopeMappingsOptimized\n }\n })\n return { imports, scopes: scopesOptimized }\n}\n", - "import { createDetailedMessage } from \"@jsenv/logger\"\nimport { resolveUrl, urlToFileSystemPath, urlToExtension } from \"@jsenv/util\"\nimport { resolveFile } from \"../resolveFile.js\"\n\nconst magicExtensions = [\".js\", \".json\", \".node\"]\n\nexport const resolvePackageMain = ({\n warn,\n packagesExportsPreference,\n packageFileUrl,\n packageJsonObject,\n}) => {\n if (packagesExportsPreference.includes(\"import\") && \"module\" in packageJsonObject) {\n return resolveMainFile({\n warn,\n packageFileUrl,\n packageMainFieldName: \"module\",\n packageMainFieldValue: packageJsonObject.module,\n })\n }\n\n if (packagesExportsPreference.includes(\"import\") && \"jsnext:main\" in packageJsonObject) {\n return resolveMainFile({\n warn,\n packageFileUrl,\n packageMainFieldName: \"jsnext:main\",\n packageMainFieldValue: packageJsonObject[\"jsnext:main\"],\n })\n }\n\n if (\n packagesExportsPreference.includes(\"browser\") &&\n \"browser\" in packageJsonObject &&\n // when it's an object it means some files\n // should be replaced with an other, let's ignore this when we are searching\n // for the main file\n typeof packageJsonObject.browser === \"string\"\n ) {\n return resolveMainFile({\n warn,\n packageFileUrl,\n packageMainFieldName: \"browser\",\n packageMainFieldValue: packageJsonObject.browser,\n })\n }\n\n if (\"main\" in packageJsonObject) {\n return resolveMainFile({\n warn,\n packageFileUrl,\n packageMainFieldName: \"main\",\n packageMainFieldValue: packageJsonObject.main,\n })\n }\n\n return resolveMainFile({\n warn,\n packageFileUrl,\n packageMainFieldName: \"default\",\n packageMainFieldValue: \"index\",\n })\n}\n\nconst resolveMainFile = async ({\n warn,\n packageFileUrl,\n packageMainFieldName,\n packageMainFieldValue,\n}) => {\n // main is explicitely empty meaning\n // it is assumed that we should not find a file\n if (packageMainFieldValue === \"\") {\n return null\n }\n\n const packageDirectoryUrl = resolveUrl(\"./\", packageFileUrl)\n const mainFileRelativeUrl = packageMainFieldValue.endsWith(\"/\")\n ? `${packageMainFieldValue}index`\n : packageMainFieldValue\n\n const mainFileUrlFirstCandidate = resolveUrl(mainFileRelativeUrl, packageFileUrl)\n\n if (!mainFileUrlFirstCandidate.startsWith(packageDirectoryUrl)) {\n warn(\n createPackageMainFileMustBeRelativeWarning({\n packageMainFieldName,\n packageMainFieldValue,\n packageFileUrl,\n }),\n )\n return null\n }\n\n const mainFileUrl = await resolveFile(mainFileUrlFirstCandidate, {\n magicExtensions,\n })\n\n if (!mainFileUrl) {\n // we know in advance this remapping does not lead to an actual file.\n // we only warn because we have no guarantee this remapping will actually be used\n // in the codebase.\n // warn only if there is actually a main field\n // otherwise the package.json is missing the main field\n // it certainly means it's not important\n if (packageMainFieldName !== \"default\") {\n warn(\n createPackageMainFileNotFoundWarning({\n specifier: packageMainFieldValue,\n importedIn: `${packageFileUrl}#${packageMainFieldName}`,\n fileUrl: mainFileUrlFirstCandidate,\n magicExtensions,\n }),\n )\n }\n return mainFileUrlFirstCandidate\n }\n\n return mainFileUrl\n}\n\nconst createPackageMainFileMustBeRelativeWarning = ({\n packageMainFieldName,\n packageMainFieldValue,\n packageFileUrl,\n}) => {\n return {\n code: \"PACKAGE_MAIN_FILE_MUST_BE_RELATIVE\",\n message: `${packageMainFieldName} field in package.json must be inside package.json folder.\n--- ${packageMainFieldName} ---\n${packageMainFieldValue}\n--- package.json path ---\n${urlToFileSystemPath(packageFileUrl)}`,\n }\n}\n\nconst createPackageMainFileNotFoundWarning = ({\n specifier,\n importedIn,\n fileUrl,\n magicExtensions,\n}) => {\n return {\n code: \"PACKAGE_MAIN_FILE_NOT_FOUND\",\n message: createDetailedMessage(`Cannot find file for \"${specifier}\"`, {\n \"imported in\": importedIn,\n \"file url tried\": fileUrl,\n ...(urlToExtension(fileUrl) === \"\"\n ? { [\"extensions tried\"]: magicExtensions.join(`, `) }\n : {}),\n }),\n }\n}\n", + "import { createDetailedMessage } from \"@jsenv/logger\"\nimport { resolveUrl, urlToFileSystemPath, urlToExtension } from \"@jsenv/util\"\nimport { resolveFile } from \"../resolveFile.js\"\n\nconst magicExtensions = [\".js\", \".json\", \".node\"]\n\nexport const resolvePackageMain = ({\n warn,\n packagesExportsPreference,\n packageFileUrl,\n packageJsonObject,\n}) => {\n if (packagesExportsPreference.includes(\"import\") && \"module\" in packageJsonObject) {\n return resolveMainFile({\n warn,\n packageFileUrl,\n packageMainFieldName: \"module\",\n packageMainFieldValue: packageJsonObject.module,\n })\n }\n\n if (packagesExportsPreference.includes(\"import\") && \"jsnext:main\" in packageJsonObject) {\n return resolveMainFile({\n warn,\n packageFileUrl,\n packageMainFieldName: \"jsnext:main\",\n packageMainFieldValue: packageJsonObject[\"jsnext:main\"],\n })\n }\n\n if (\n packagesExportsPreference.includes(\"browser\") &&\n \"browser\" in packageJsonObject &&\n // when it's an object it means some files\n // should be replaced with an other, let's ignore this when we are searching\n // for the main file\n typeof packageJsonObject.browser === \"string\"\n ) {\n return resolveMainFile({\n warn,\n packageFileUrl,\n packageMainFieldName: \"browser\",\n packageMainFieldValue: packageJsonObject.browser,\n })\n }\n\n if (\"main\" in packageJsonObject) {\n return resolveMainFile({\n warn,\n packageFileUrl,\n packageMainFieldName: \"main\",\n packageMainFieldValue: packageJsonObject.main,\n })\n }\n\n return resolveMainFile({\n warn,\n packageFileUrl,\n packageMainFieldName: \"default\",\n packageMainFieldValue: \"index\",\n })\n}\n\nconst resolveMainFile = async ({\n warn,\n packageFileUrl,\n packageMainFieldName,\n packageMainFieldValue,\n}) => {\n // main is explicitely empty meaning\n // it is assumed that we should not find a file\n if (packageMainFieldValue === \"\") {\n return null\n }\n\n const packageDirectoryUrl = resolveUrl(\"./\", packageFileUrl)\n const mainFileRelativeUrl = packageMainFieldValue.endsWith(\"/\")\n ? `${packageMainFieldValue}index`\n : packageMainFieldValue\n\n const mainFileUrlFirstCandidate = resolveUrl(mainFileRelativeUrl, packageFileUrl)\n\n if (!mainFileUrlFirstCandidate.startsWith(packageDirectoryUrl)) {\n warn(\n createPackageMainFileMustBeRelativeWarning({\n packageMainFieldName,\n packageMainFieldValue,\n packageFileUrl,\n }),\n )\n return null\n }\n\n const mainFileUrl = await resolveFile(mainFileUrlFirstCandidate, {\n magicExtensions,\n })\n\n if (!mainFileUrl) {\n // we know in advance this remapping does not lead to an actual file.\n // we only warn because we have no guarantee this remapping will actually be used\n // in the codebase.\n // warn only if there is actually a main field\n // otherwise the package.json is missing the main field\n // it certainly means it's not important\n if (packageMainFieldName !== \"default\") {\n warn(\n createPackageMainFileNotFoundWarning({\n specifier: packageMainFieldValue,\n importedIn: `${packageFileUrl}#${packageMainFieldName}`,\n fileUrl: mainFileUrlFirstCandidate,\n magicExtensions,\n }),\n )\n }\n return mainFileUrlFirstCandidate\n }\n\n return mainFileUrl\n}\n\nconst createPackageMainFileMustBeRelativeWarning = ({\n packageMainFieldName,\n packageMainFieldValue,\n packageFileUrl,\n}) => {\n return {\n code: \"PACKAGE_MAIN_FILE_MUST_BE_RELATIVE\",\n message: `${packageMainFieldName} field in package.json must be inside package.json folder.\n--- ${packageMainFieldName} ---\n${packageMainFieldValue}\n--- package.json path ---\n${urlToFileSystemPath(packageFileUrl)}`,\n }\n}\n\nconst createPackageMainFileNotFoundWarning = ({\n specifier,\n importedIn,\n fileUrl,\n magicExtensions,\n}) => {\n return {\n code: \"PACKAGE_MAIN_FILE_NOT_FOUND\",\n message: createDetailedMessage(`Cannot find package main file \"${specifier}\"`, {\n \"imported in\": importedIn,\n \"file url tried\": fileUrl,\n ...(urlToExtension(fileUrl) === \"\"\n ? { [\"extensions tried\"]: magicExtensions.join(`, `) }\n : {}),\n }),\n }\n}\n", "import { resolveUrl, moveImportMap } from \"@jsenv/import-map\"\nimport { readFile, urlToFileSystemPath } from \"@jsenv/util\"\n\nexport const visitPackageImportMap = async ({\n warn,\n packageFileUrl,\n packageJsonObject,\n packageImportmap = packageJsonObject.importmap,\n projectDirectoryUrl,\n}) => {\n if (typeof packageImportmap === \"undefined\") {\n return {}\n }\n\n if (typeof packageImportmap === \"string\") {\n const importmapFileUrl = resolveUrl(packageImportmap, packageFileUrl)\n const importmap = await readFile(importmapFileUrl, { as: \"json\" })\n return moveImportMap(importmap, importmapFileUrl, projectDirectoryUrl)\n }\n\n if (typeof packageImportmap === \"object\" && packageImportmap !== null) {\n return packageImportmap\n }\n\n warn(\n createPackageImportMapUnexpectedWarning({\n packageImportmap,\n packageFileUrl,\n }),\n )\n return {}\n}\n\nconst createPackageImportMapUnexpectedWarning = ({ packageImportmap, packageFileUrl }) => {\n return {\n code: \"PACKAGE_IMPORTMAP_UNEXPECTED\",\n message: `unexpected value in package.json importmap field: value must be a string or an object.\n--- value ---\n${packageImportmap}\n--- package.json path ---\n${urlToFileSystemPath(packageFileUrl)}`,\n }\n}\n", "export const specifierIsRelative = (specifier) => {\n if (specifier.startsWith(\"//\")) {\n return false\n }\n if (specifier.startsWith(\"../\")) {\n return false\n }\n // starts with http:// or file:// or ftp: for instance\n if (/^[a-zA-Z]+\\:/.test(specifier)) {\n return false\n }\n return true\n}\n", "// https://nodejs.org/dist/latest-v13.x/docs/api/esm.html#esm_package_exports\n\nimport { urlToFileSystemPath, urlToRelativeUrl, resolveUrl } from \"@jsenv/util\"\nimport { specifierIsRelative } from \"./specifierIsRelative.js\"\n\nexport const visitPackageExports = ({\n warn,\n packageFileUrl,\n packageJsonObject,\n packageExports = packageJsonObject.exports,\n packageName = packageJsonObject.name,\n projectDirectoryUrl,\n packagesExportsPreference,\n onExport,\n}) => {\n const packageDirectoryUrl = resolveUrl(\"./\", packageFileUrl)\n const packageDirectoryRelativeUrl = urlToRelativeUrl(packageDirectoryUrl, projectDirectoryUrl)\n\n visitExportsSubpath(packageExports, packagesExportsPreference, {\n onUnexpectedPackageExports: ({ packageExportsValue, packageExportsValuePath }) => {\n warn(\n createExportsValueWarning({\n packageExportsValue,\n packageExportsValuePath,\n packageFileUrl,\n }),\n )\n },\n onMixedPackageExports: ({ packageExportsValue, packageExportsValuePath }) => {\n // see https://nodejs.org/dist/latest-v13.x/docs/api/esm.html#esm_exports_sugar\n warn(\n createExportsMixedWarning({\n packageExportsValue,\n packageExportsValuePath,\n packageFileUrl,\n }),\n )\n },\n onSubpathPackageExport: ({ key, value, valuePath }) => {\n if (!specifierIsRelative(key)) {\n warn(\n createExportsMappingKeyMustBeRelativeWarning({\n key,\n keyPath: valuePath.slice(0, -1),\n packageFileUrl,\n }),\n )\n return\n }\n if (typeof value !== \"string\") {\n warn(\n createExportsMappingValueMustBeAStringWarning({\n value,\n valuePath,\n packageFileUrl,\n }),\n )\n return\n }\n if (!specifierIsRelative(value)) {\n warn(\n createExportsMappingValueMustBeRelativeWarning({\n value,\n valuePath,\n packageFileUrl,\n }),\n )\n return\n }\n\n onExport({\n key: specifierToSource(key, packageName),\n value: addressToDestination(value, packageDirectoryRelativeUrl),\n })\n },\n })\n}\n\nconst visitExportsSubpath = (\n packageExports,\n packageExportsConditions,\n { onUnexpectedPackageExports, onMixedPackageExports, onSubpathPackageExport },\n) => {\n const visitValue = (packageExportsValue, { valuePath }) => {\n // false is allowed as alternative to exports: {}\n if (packageExportsValue === false) {\n return\n }\n\n if (typeof packageExportsValue === \"string\") {\n const firstNonConditionKey = valuePath\n .slice()\n .reverse()\n .find((key) => key.startsWith(\".\"))\n const key = firstNonConditionKey || \".\"\n onSubpathPackageExport({\n value: packageExportsValue,\n valuePath,\n key,\n })\n return\n }\n\n if (typeof packageExportsValue !== \"object\" && packageExportsValue !== null) {\n onUnexpectedPackageExports({\n packageExportsValue,\n packageExportsValuePath: valuePath,\n })\n return\n }\n\n const keys = Object.keys(packageExportsValue)\n const everyKeyDoesNotStartsWithDot = keys.every((key) => !key.startsWith(\".\"))\n if (everyKeyDoesNotStartsWithDot) {\n const bestConditionKey = findBestConditionKey(keys, packageExportsConditions)\n if (!bestConditionKey) {\n return\n }\n const bestExports = packageExportsValue[bestConditionKey]\n visitValue(bestExports, {\n valuePath: [...valuePath, bestConditionKey],\n })\n return\n }\n\n const everyKeyStartsWithDot = keys.every((key) => key.startsWith(\".\"))\n if (everyKeyStartsWithDot) {\n keys.forEach((key) => {\n visitValue(packageExportsValue[key], {\n valuePath: [...valuePath, key],\n })\n })\n return\n }\n\n onMixedPackageExports({\n packageExportsValue,\n packageExportsValuePath: valuePath,\n })\n }\n visitValue(packageExports, {\n valuePath: [\"exports\"],\n })\n}\n\nconst findBestConditionKey = (availableKeys, exportsConditions) => {\n const conditionKey = exportsConditions.find((key) => availableKeys.includes(key))\n if (conditionKey) {\n return conditionKey\n }\n\n if (availableKeys.includes(\"default\")) {\n return \"default\"\n }\n\n return undefined\n}\n\nconst specifierToSource = (specifier, packageName) => {\n if (specifier === \".\") {\n return packageName\n }\n\n if (specifier[0] === \"/\") {\n return specifier\n }\n\n if (specifier.startsWith(\"./\")) {\n return `${packageName}${specifier.slice(1)}`\n }\n\n return `${packageName}/${specifier}`\n}\n\nconst addressToDestination = (address, packageDirectoryRelativeUrl) => {\n if (address[0] === \"/\") {\n return address\n }\n\n if (address.startsWith(\"./\")) {\n return `./${packageDirectoryRelativeUrl}${address.slice(2)}`\n }\n\n return `./${packageDirectoryRelativeUrl}${address}`\n}\n\nconst createExportsValueWarning = ({\n packageExportsValue,\n packageExportsValuePath,\n packageFileUrl,\n}) => {\n return {\n code: \"EXPORTS_VALUE\",\n message: `unexpected value in package.json exports field: value must be an object or a string.\n--- value ---\n${packageExportsValue}\n--- value path ---\n${packageExportsValuePath.join(\".\")}\n--- package.json path ---\n${urlToFileSystemPath(packageFileUrl)}`,\n }\n}\n\nconst createExportsMixedWarning = ({\n packageExportsValue,\n packageExportsValuePath,\n packageFileUrl,\n}) => {\n return {\n code: \"EXPORTS_MIXED\",\n message: `unexpected package.json exports field: cannot mix conditional and subpath exports.\n--- value ---\n${JSON.stringify(packageExportsValue, null, \" \")}\n--- value path ---\n${packageExportsValuePath.join(\".\")}\n--- package.json path ---\n${urlToFileSystemPath(packageFileUrl)}`,\n }\n}\n\nconst createExportsMappingKeyMustBeRelativeWarning = ({ key, keyPath, packageFileUrl }) => {\n return {\n code: \"EXPORTS_MAPPING_KEY_MUST_BE_RELATIVE\",\n message: `unexpected key in package.json exports field: key must be relative.\n--- key ---\n${key}\n--- key path ---\n${keyPath.join(\".\")}\n--- package.json path ---\n${urlToFileSystemPath(packageFileUrl)}`,\n }\n}\n\nconst createExportsMappingValueMustBeAStringWarning = ({ value, valuePath, packageFileUrl }) => {\n return {\n code: \"EXPORTS_MAPPING_VALUE_MUST_BE_A_STRING\",\n message: `unexpected value in package.json exports field: value must be a string.\n--- value ---\n${value}\n--- value path ---\n${valuePath.join(\".\")}\n--- package.json path ---\n${urlToFileSystemPath(packageFileUrl)}`,\n }\n}\n\nconst createExportsMappingValueMustBeRelativeWarning = ({ value, valuePath, packageFileUrl }) => {\n return {\n code: \"EXPORTS_MAPPING_VALUE_MUST_BE_RELATIVE\",\n message: `unexpected value in package.json exports field: value must be relative.\n--- value ---\n${value}\n--- value path ---\n${valuePath.join(\".\")}\n--- package.json path ---\n${urlToFileSystemPath(packageFileUrl)}`,\n }\n}\n", "export const applyPackageManualOverride = (packageObject, packagesManualOverrides) => {\n const { name, version } = packageObject\n const overrideKey = Object.keys(packagesManualOverrides).find((overrideKeyCandidate) => {\n if (name === overrideKeyCandidate) {\n return true\n }\n if (`${name}@${version}` === overrideKeyCandidate) {\n return true\n }\n return false\n })\n if (overrideKey) {\n return composeObject(packageObject, packagesManualOverrides[overrideKey])\n }\n return packageObject\n}\n\nconst composeObject = (leftObject, rightObject) => {\n const composedObject = {\n ...leftObject,\n }\n Object.keys(rightObject).forEach((key) => {\n const rightValue = rightObject[key]\n\n if (rightValue === null || typeof rightValue !== \"object\" || key in leftObject === false) {\n composedObject[key] = rightValue\n } else {\n const leftValue = leftObject[key]\n if (leftValue === null || typeof leftValue !== \"object\") {\n composedObject[key] = rightValue\n } else {\n composedObject[key] = composeObject(leftValue, rightValue)\n }\n }\n })\n return composedObject\n}\n", "import { readFile, urlToFileSystemPath } from \"@jsenv/util\"\nimport { applyPackageManualOverride } from \"./applyPackageManualOverride.js\"\n\nexport const PACKAGE_NOT_FOUND = {}\nexport const PACKAGE_WITH_SYNTAX_ERROR = {}\n\nexport const readPackageFile = async (packageFileUrl, packagesManualOverrides) => {\n try {\n const packageObject = await readFile(packageFileUrl, { as: \"json\" })\n return applyPackageManualOverride(packageObject, packagesManualOverrides)\n } catch (e) {\n if (e.code === \"ENOENT\") {\n return PACKAGE_NOT_FOUND\n }\n\n if (e.name === \"SyntaxError\") {\n console.error(formatPackageSyntaxErrorLog({ syntaxError: e, packageFileUrl }))\n return PACKAGE_WITH_SYNTAX_ERROR\n }\n\n throw e\n }\n}\n\nconst formatPackageSyntaxErrorLog = ({ syntaxError, packageFileUrl }) => {\n return `\nerror while parsing package.json.\n--- syntax error message ---\n${syntaxError.message}\n--- package.json path ---\n${urlToFileSystemPath(packageFileUrl)}\n`\n}\n", - "import { firstOperationMatching } from \"@jsenv/cancellation\"\nimport { urlToRelativeUrl, resolveUrl } from \"@jsenv/util\"\nimport { memoizeAsyncFunctionByUrl } from \"../memoizeAsyncFunction.js\"\nimport { readPackageFile, PACKAGE_NOT_FOUND, PACKAGE_WITH_SYNTAX_ERROR } from \"./readPackageFile.js\"\n\nexport const createFindNodeModulePackage = (packagesManualOverrides) => {\n const readPackageFileMemoized = memoizeAsyncFunctionByUrl((packageFileUrl) => {\n return readPackageFile(packageFileUrl, packagesManualOverrides)\n })\n\n return ({ projectDirectoryUrl, packageFileUrl, dependencyName }) => {\n const nodeModuleCandidates = getNodeModuleCandidates(packageFileUrl, projectDirectoryUrl)\n\n return firstOperationMatching({\n array: nodeModuleCandidates,\n start: async (nodeModuleCandidate) => {\n const packageFileUrlCandidate = `${projectDirectoryUrl}${nodeModuleCandidate}${dependencyName}/package.json`\n const packageObjectCandidate = await readPackageFileMemoized(packageFileUrlCandidate)\n return {\n packageFileUrl: packageFileUrlCandidate,\n packageJsonObject: packageObjectCandidate,\n }\n },\n predicate: ({ packageJsonObject }) => {\n return (\n packageJsonObject !== PACKAGE_NOT_FOUND && packageJsonObject !== PACKAGE_WITH_SYNTAX_ERROR\n )\n },\n })\n }\n}\n\nconst getNodeModuleCandidates = (fileUrl, projectDirectoryUrl) => {\n const fileDirectoryUrl = resolveUrl(\"./\", fileUrl)\n\n if (fileDirectoryUrl === projectDirectoryUrl) {\n return [`node_modules/`]\n }\n\n const fileDirectoryRelativeUrl = urlToRelativeUrl(fileDirectoryUrl, projectDirectoryUrl)\n const candidates = []\n const relativeNodeModuleDirectoryArray = fileDirectoryRelativeUrl.split(\"node_modules/\")\n // remove the first empty string\n relativeNodeModuleDirectoryArray.shift()\n\n let i = relativeNodeModuleDirectoryArray.length\n while (i--) {\n candidates.push(\n `node_modules/${relativeNodeModuleDirectoryArray\n .slice(0, i + 1)\n .join(\"node_modules/\")}node_modules/`,\n )\n }\n\n return [...candidates, \"node_modules/\"]\n}\n", - "import { createDetailedMessage } from \"@jsenv/logger\"\nimport {\n resolveUrl,\n urlToRelativeUrl,\n assertAndNormalizeDirectoryUrl,\n urlToFileSystemPath,\n urlToBasename,\n readFile,\n} from \"@jsenv/util\"\nimport { optimizeImportMap } from \"../optimizeImportMap.js\"\nimport { resolvePackageMain } from \"./resolvePackageMain.js\"\nimport { visitPackageImportMap } from \"./visitPackageImportMap.js\"\nimport { visitPackageExports } from \"./visitPackageExports.js\"\nimport { createFindNodeModulePackage } from \"./node-module-resolution.js\"\n\nexport const getImportMapFromPackageFiles = async ({\n // nothing is actually listening for this cancellationToken for now\n // it's not very important but it would be better to register on it\n // an stops what we are doing if asked to do so\n // cancellationToken = createCancellationTokenForProcess(),\n logger,\n warn,\n projectDirectoryUrl,\n projectPackageDevDependenciesIncluded = process.env.NODE_ENV !== \"production\",\n packagesExportsPreference = [\"import\", \"browser\"],\n packagesExportsIncluded = true,\n packagesManualOverrides = {},\n packageIncludedPredicate = () => true,\n}) => {\n projectDirectoryUrl = assertAndNormalizeDirectoryUrl(projectDirectoryUrl)\n\n const projectPackageFileUrl = resolveUrl(\"./package.json\", projectDirectoryUrl)\n const findNodeModulePackage = createFindNodeModulePackage(packagesManualOverrides)\n\n const imports = {}\n const scopes = {}\n const addTopLevelImportMapping = ({ from, to }) => {\n // we could think it's useless to remap from with to\n // however it can be used to ensure a weaker remapping\n // does not win over this specific file or folder\n if (from === to) {\n /**\n * however remapping '/' to '/' is truly useless\n * moreover it would make wrapImportMap create something like\n * {\n * imports: {\n * \"/\": \"/.dist/best/\"\n * }\n * }\n * that would append the wrapped folder twice\n * */\n if (from === \"/\") return\n }\n\n imports[from] = to\n }\n const addScopedImportMapping = ({ scope, from, to }) => {\n // when a package says './' maps to './'\n // we must add something to say if we are already inside the package\n // no need to ensure leading slash are scoped to the package\n if (from === \"./\" && to === scope) {\n addScopedImportMapping({\n scope,\n from: scope,\n to: scope,\n })\n const packageName = scope.slice(scope.lastIndexOf(\"node_modules/\") + `node_modules/`.length)\n addScopedImportMapping({\n scope,\n from: packageName,\n to: scope,\n })\n }\n\n scopes[scope] = {\n ...(scopes[scope] || {}),\n [from]: to,\n }\n }\n\n const seen = {}\n const markPackageAsSeen = (packageFileUrl, importerPackageFileUrl) => {\n if (packageFileUrl in seen) {\n seen[packageFileUrl].push(importerPackageFileUrl)\n } else {\n seen[packageFileUrl] = [importerPackageFileUrl]\n }\n }\n const packageIsSeen = (packageFileUrl, importerPackageFileUrl) => {\n return packageFileUrl in seen && seen[packageFileUrl].includes(importerPackageFileUrl)\n }\n\n const visit = async ({\n packageFileUrl,\n packageName,\n packageJsonObject,\n importerPackageFileUrl,\n importerPackageJsonObject,\n includeDevDependencies,\n }) => {\n if (!packageIncludedPredicate({ packageName, packageFileUrl, packageJsonObject })) {\n return\n }\n\n await visitDependencies({\n packageFileUrl,\n packageJsonObject,\n includeDevDependencies,\n })\n await visitPackage({\n packageFileUrl,\n packageName,\n packageJsonObject,\n importerPackageFileUrl,\n importerPackageJsonObject,\n })\n }\n\n const visitPackage = async ({\n packageFileUrl,\n packageName,\n packageJsonObject,\n importerPackageFileUrl,\n }) => {\n const packageInfo = computePackageInfo({\n packageFileUrl,\n packageName,\n importerPackageFileUrl,\n })\n\n await visitPackageMain({\n packageFileUrl,\n packageName,\n packageJsonObject,\n packageInfo,\n })\n\n const {\n importerIsRoot,\n importerRelativeUrl,\n packageIsRoot,\n packageDirectoryRelativeUrl,\n // packageDirectoryUrl,\n // packageDirectoryUrlExpected,\n } = packageInfo\n\n const addImportMapForPackage = (importMap) => {\n if (packageIsRoot) {\n const { imports = {}, scopes = {} } = importMap\n Object.keys(imports).forEach((from) => {\n addTopLevelImportMapping({\n from,\n to: imports[from],\n })\n })\n Object.keys(scopes).forEach((scope) => {\n const scopeMappings = scopes[scope]\n Object.keys(scopeMappings).forEach((key) => {\n addScopedImportMapping({\n scope,\n from: key,\n to: scopeMappings[key],\n })\n })\n })\n return\n }\n\n const { imports = {}, scopes = {} } = importMap\n const scope = `./${packageDirectoryRelativeUrl}`\n Object.keys(imports).forEach((from) => {\n const to = imports[from]\n const toMoved = moveMappingValue(to, packageFileUrl, projectDirectoryUrl)\n addScopedImportMapping({\n scope,\n from,\n to: toMoved,\n })\n })\n Object.keys(scopes).forEach((scope) => {\n const scopeMappings = scopes[scope]\n const scopeMoved = moveMappingValue(scope, packageFileUrl, projectDirectoryUrl)\n Object.keys(scopeMappings).forEach((key) => {\n const to = scopeMappings[key]\n const toMoved = moveMappingValue(to, packageFileUrl, projectDirectoryUrl)\n addScopedImportMapping({\n scope: scopeMoved,\n from: key,\n to: toMoved,\n })\n })\n })\n }\n\n const addMappingsForPackageAndImporter = (mappings) => {\n if (packageIsRoot) {\n Object.keys(mappings).forEach((from) => {\n const to = mappings[from]\n addTopLevelImportMapping({\n from,\n to,\n })\n })\n return\n }\n\n if (importerIsRoot) {\n // own package mappings available to himself\n Object.keys(mappings).forEach((from) => {\n const to = mappings[from]\n addScopedImportMapping({\n scope: `./${packageDirectoryRelativeUrl}`,\n from,\n to,\n })\n addTopLevelImportMapping({ from, to })\n })\n\n // if importer is root no need to make package mappings available to the importer\n // because they are already on top level mappings\n return\n }\n\n Object.keys(mappings).forEach((from) => {\n const to = mappings[from]\n // own package exports available to himself\n addScopedImportMapping({\n scope: `./${packageDirectoryRelativeUrl}`,\n from,\n to,\n })\n // now make package exports available to the importer\n // here if the importer is himself we could do stuff\n // we should even handle the case earlier to prevent top level remapping\n addScopedImportMapping({\n scope: `./${importerRelativeUrl}`,\n from,\n to,\n })\n })\n }\n\n const importsFromPackageField = await visitPackageImportMap({\n warn,\n packageFileUrl,\n packageJsonObject,\n projectDirectoryUrl,\n })\n addImportMapForPackage(importsFromPackageField)\n\n if (packagesExportsIncluded && \"exports\" in packageJsonObject) {\n const mappingsFromPackageExports = {}\n visitPackageExports({\n warn,\n packageFileUrl,\n packageJsonObject,\n packageName,\n projectDirectoryUrl,\n packagesExportsPreference,\n onExport: ({ key, value }) => {\n const from = key\n const to = value\n\n if (from.indexOf(\"*\") === -1) {\n mappingsFromPackageExports[from] = to\n return\n }\n\n if (\n from.endsWith(\"/*\") &&\n to.endsWith(\"/*\") &&\n // ensure ends with '*' AND there is only one '*' occurence\n to.indexOf(\"*\") === to.length - 1\n ) {\n const fromWithouTrailingStar = from.slice(0, -1)\n const toWithoutTrailingStar = to.slice(0, -1)\n mappingsFromPackageExports[fromWithouTrailingStar] = toWithoutTrailingStar\n return\n }\n\n warn(\n createExportsWildcardIgnoredWarning({\n key,\n value,\n packageFileUrl,\n }),\n )\n },\n })\n addMappingsForPackageAndImporter(mappingsFromPackageExports)\n }\n }\n\n const visitPackageMain = async ({\n packageFileUrl,\n packageName,\n packageJsonObject,\n packageInfo: {\n importerIsRoot,\n importerRelativeUrl,\n packageDirectoryUrl,\n packageDirectoryUrlExpected,\n },\n }) => {\n const mainFileUrl = await resolvePackageMain({\n warn,\n packagesExportsPreference,\n packageFileUrl,\n packageJsonObject,\n })\n\n // it's possible to have no main\n // like { main: \"\" } in package.json\n // or a main that does not lead to an actual file\n if (mainFileUrl === null) {\n return\n }\n\n const mainFileRelativeUrl = urlToRelativeUrl(mainFileUrl, projectDirectoryUrl)\n const from = packageName\n const to = `./${mainFileRelativeUrl}`\n\n if (importerIsRoot) {\n addTopLevelImportMapping({ from, to })\n } else {\n addScopedImportMapping({\n scope: `./${importerRelativeUrl}`,\n from,\n to,\n })\n }\n if (packageDirectoryUrl !== packageDirectoryUrlExpected) {\n addScopedImportMapping({\n scope: `./${importerRelativeUrl}`,\n from,\n to,\n })\n }\n }\n\n const visitDependencies = async ({\n packageFileUrl,\n packageJsonObject,\n includeDevDependencies,\n }) => {\n const dependencyMap = packageDependenciesFromPackageObject(packageJsonObject, {\n includeDevDependencies,\n })\n\n await Promise.all(\n Object.keys(dependencyMap).map(async (dependencyName) => {\n const dependencyInfo = dependencyMap[dependencyName]\n await visitDependency({\n packageFileUrl,\n packageJsonObject,\n dependencyName,\n dependencyInfo,\n })\n }),\n )\n }\n\n const visitDependency = async ({\n packageFileUrl,\n packageJsonObject,\n dependencyName,\n dependencyInfo,\n }) => {\n const dependencyData = await findDependency({\n packageFileUrl,\n dependencyName,\n })\n if (!dependencyData) {\n const cannotFindPackageWarning = createCannotFindPackageWarning({\n dependencyName,\n dependencyInfo,\n packageFileUrl,\n })\n if (dependencyInfo.isOptional) {\n logger.debug(cannotFindPackageWarning.message)\n } else {\n warn(cannotFindPackageWarning)\n }\n\n return\n }\n\n const {\n packageFileUrl: dependencyPackageFileUrl,\n packageJsonObject: dependencyPackageJsonObject,\n } = dependencyData\n\n if (packageIsSeen(dependencyPackageFileUrl, packageFileUrl)) {\n return\n }\n markPackageAsSeen(dependencyPackageFileUrl, packageFileUrl)\n await visit({\n packageFileUrl: dependencyPackageFileUrl,\n packageName: dependencyName,\n packageJsonObject: dependencyPackageJsonObject,\n importerPackageFileUrl: packageFileUrl,\n importerPackageJsonObject: packageJsonObject,\n })\n }\n\n const computePackageInfo = ({ packageFileUrl, packageName, importerPackageFileUrl }) => {\n const importerIsRoot = importerPackageFileUrl === projectPackageFileUrl\n\n const importerPackageDirectoryUrl = resolveUrl(\"./\", importerPackageFileUrl)\n\n const importerRelativeUrl = importerIsRoot\n ? `${urlToBasename(projectDirectoryUrl.slice(0, -1))}/`\n : urlToRelativeUrl(importerPackageDirectoryUrl, projectDirectoryUrl)\n\n const packageIsRoot = packageFileUrl === projectPackageFileUrl\n\n const packageDirectoryUrl = resolveUrl(\"./\", packageFileUrl)\n\n const packageDirectoryUrlExpected = `${importerPackageDirectoryUrl}node_modules/${packageName}/`\n\n const packageDirectoryRelativeUrl = urlToRelativeUrl(packageDirectoryUrl, projectDirectoryUrl)\n\n return {\n importerIsRoot,\n importerRelativeUrl,\n packageIsRoot,\n packageDirectoryUrl,\n packageDirectoryUrlExpected,\n packageDirectoryRelativeUrl,\n }\n }\n\n const dependenciesCache = {}\n const findDependency = ({ packageFileUrl, dependencyName }) => {\n if (packageFileUrl in dependenciesCache === false) {\n dependenciesCache[packageFileUrl] = {}\n }\n if (dependencyName in dependenciesCache[packageFileUrl]) {\n return dependenciesCache[packageFileUrl][dependencyName]\n }\n const dependencyPromise = findNodeModulePackage({\n projectDirectoryUrl,\n packageFileUrl,\n dependencyName,\n })\n dependenciesCache[packageFileUrl][dependencyName] = dependencyPromise\n return dependencyPromise\n }\n\n const projectPackageJsonObject = await readFile(projectPackageFileUrl, { as: \"json\" })\n const importerPackageFileUrl = projectPackageFileUrl\n markPackageAsSeen(projectPackageFileUrl, importerPackageFileUrl)\n\n const packageName = projectPackageJsonObject.name\n if (typeof packageName !== \"string\") {\n warn(\n createPackageNameMustBeAStringWarning({\n packageName,\n packageFileUrl: projectPackageFileUrl,\n }),\n )\n return {}\n }\n\n await visit({\n packageFileUrl: projectPackageFileUrl,\n packageName: projectPackageJsonObject.name,\n packageJsonObject: projectPackageJsonObject,\n importerPackageFileUrl,\n importerPackageJsonObject: null,\n includeDevDependencies: projectPackageDevDependenciesIncluded,\n })\n\n return optimizeImportMap({ imports, scopes })\n}\n\nconst packageDependenciesFromPackageObject = (packageObject, { includeDevDependencies }) => {\n const packageDependencies = {}\n\n const { dependencies = {} } = packageObject\n // https://npm.github.io/using-pkgs-docs/package-json/types/optionaldependencies.html\n const { optionalDependencies = {} } = packageObject\n Object.keys(dependencies).forEach((dependencyName) => {\n packageDependencies[dependencyName] = {\n type: \"dependency\",\n isOptional: dependencyName in optionalDependencies,\n versionPattern: dependencies[dependencyName],\n }\n })\n\n const { peerDependencies = {} } = packageObject\n const { peerDependenciesMeta = {} } = packageObject\n Object.keys(peerDependencies).forEach((dependencyName) => {\n packageDependencies[dependencyName] = {\n type: \"peerDependency\",\n versionPattern: peerDependencies[dependencyName],\n isOptional:\n dependencyName in peerDependenciesMeta && peerDependenciesMeta[dependencyName].optional,\n }\n })\n\n if (includeDevDependencies) {\n const { devDependencies = {} } = packageObject\n Object.keys(devDependencies).forEach((dependencyName) => {\n if (!packageDependencies.hasOwnProperty(dependencyName)) {\n packageDependencies[dependencyName] = {\n type: \"devDependency\",\n versionPattern: devDependencies[dependencyName],\n }\n }\n })\n }\n\n return packageDependencies\n}\n\nconst moveMappingValue = (address, from, to) => {\n const url = resolveUrl(address, from)\n const relativeUrl = urlToRelativeUrl(url, to)\n if (relativeUrl.startsWith(\"../\")) {\n return relativeUrl\n }\n if (relativeUrl.startsWith(\"./\")) {\n return relativeUrl\n }\n if (/^[a-zA-Z]{2,}:/.test(relativeUrl)) {\n // has sheme\n return relativeUrl\n }\n return `./${relativeUrl}`\n}\n\nconst createExportsWildcardIgnoredWarning = ({ key, value, packageFileUrl }) => {\n return {\n code: \"EXPORTS_WILDCARD\",\n message: `Ignoring export using \"*\" because it is not supported by importmap.\n--- key ---\n${key}\n--- value ---\n${value}\n--- package.json path ---\n${urlToFileSystemPath(packageFileUrl)}\n--- see also ---\nhttps://github.com/WICG/import-maps/issues/232`,\n }\n}\n\nconst createPackageNameMustBeAStringWarning = ({ packageName, packageFileUrl }) => {\n return {\n code: \"PACKAGE_NAME_MUST_BE_A_STRING\",\n message: `package name field must be a string\n--- package name field ---\n${packageName}\n--- package.json file path ---\n${packageFileUrl}`,\n }\n}\n\nconst createCannotFindPackageWarning = ({ dependencyName, dependencyInfo, packageFileUrl }) => {\n const dependencyIsOptional = dependencyInfo.isOptional\n const dependencyType = dependencyInfo.type\n const dependencyVersionPattern = dependencyInfo.versionPattern\n return {\n code: \"CANNOT_FIND_PACKAGE\",\n message: createDetailedMessage(\n dependencyIsOptional\n ? `cannot find an optional ${dependencyType}.`\n : `cannot find a ${dependencyType}.`,\n {\n [dependencyType]: `${dependencyName}@${dependencyVersionPattern}`,\n \"required by\": urlToFileSystemPath(packageFileUrl),\n },\n ),\n }\n}\n", - "import { sortImportMap, composeTwoImportMaps } from \"@jsenv/import-map\"\nimport { createLogger } from \"@jsenv/logger\"\nimport { getImportMapFromJsFiles } from \"./internal/from-js/getImportMapFromJsFiles.js\"\nimport { getImportMapFromPackageFiles } from \"./internal/from-package/getImportMapFromPackageFiles.js\"\n\nexport const getImportMapFromProjectFiles = async ({\n logLevel,\n projectDirectoryUrl,\n runtime = \"browser\",\n moduleFormat = \"esm\",\n dev = false,\n jsFiles = false,\n removeUnusedMappings = !dev,\n magicExtensions,\n onWarn = (warning, warn) => {\n warn(warning)\n },\n ...rest\n}) => {\n const packagesExportsPreference = [\n ...(moduleFormatPreferences[moduleFormat] || [moduleFormat]),\n ...(runtimeExportsPreferences[runtime] || [runtime]),\n ...(dev ? \"development\" : \"production\"),\n ]\n\n const logger = createLogger({ logLevel })\n const warn = (warning) => {\n onWarn(warning, () => {\n logger.warn(`\\n${warning.message}\\n`)\n })\n }\n\n // At this point, importmap is relative to the project directory url\n let importMapFromPackageFiles = await getImportMapFromPackageFiles({\n logger,\n warn,\n projectDirectoryUrl,\n packagesExportsPreference,\n projectPackageDevDependenciesIncluded: dev,\n ...rest,\n })\n importMapFromPackageFiles = sortImportMap(importMapFromPackageFiles)\n\n let importMapFromJsFiles = jsFiles\n ? await getImportMapFromJsFiles({\n logLevel,\n warn,\n importMap: importMapFromPackageFiles,\n removeUnusedMappings,\n projectDirectoryUrl,\n magicExtensions,\n packagesExportsPreference,\n runtime,\n })\n : {}\n importMapFromJsFiles = sortImportMap(importMapFromJsFiles)\n\n return sortImportMap(composeTwoImportMaps(importMapFromPackageFiles, importMapFromJsFiles))\n}\n\nconst runtimeExportsPreferences = {\n browser: [\"browser\"],\n node: [\"node\"],\n}\n\nconst moduleFormatPreferences = {\n esm: [\"import\"],\n cjs: [\"require\"],\n}\n", + "import { firstOperationMatching } from \"@jsenv/cancellation\"\nimport { urlToRelativeUrl, resolveUrl } from \"@jsenv/util\"\nimport { memoizeAsyncFunctionByUrl } from \"../memoizeAsyncFunction.js\"\nimport { readPackageFile, PACKAGE_NOT_FOUND, PACKAGE_WITH_SYNTAX_ERROR } from \"./readPackageFile.js\"\n\nexport const createFindNodeModulePackage = (packagesManualOverrides) => {\n const readPackageFileMemoized = memoizeAsyncFunctionByUrl((packageFileUrl) => {\n return readPackageFile(packageFileUrl, packagesManualOverrides)\n })\n\n return ({ projectDirectoryUrl, packageFileUrl, dependencyName }) => {\n const nodeModuleCandidates = getNodeModuleCandidates(packageFileUrl, projectDirectoryUrl)\n\n return firstOperationMatching({\n array: nodeModuleCandidates,\n start: async (nodeModuleCandidate) => {\n const packageFileUrlCandidate = `${projectDirectoryUrl}${nodeModuleCandidate}${dependencyName}/package.json`\n const packageObjectCandidate = await readPackageFileMemoized(packageFileUrlCandidate)\n return {\n packageFileUrl: packageFileUrlCandidate,\n packageJsonObject: packageObjectCandidate,\n syntaxError: packageObjectCandidate === PACKAGE_WITH_SYNTAX_ERROR,\n }\n },\n predicate: ({ packageJsonObject }) => {\n return packageJsonObject !== PACKAGE_NOT_FOUND\n },\n })\n }\n}\n\nconst getNodeModuleCandidates = (fileUrl, projectDirectoryUrl) => {\n const fileDirectoryUrl = resolveUrl(\"./\", fileUrl)\n\n if (fileDirectoryUrl === projectDirectoryUrl) {\n return [`node_modules/`]\n }\n\n const fileDirectoryRelativeUrl = urlToRelativeUrl(fileDirectoryUrl, projectDirectoryUrl)\n const candidates = []\n const relativeNodeModuleDirectoryArray = fileDirectoryRelativeUrl.split(\"node_modules/\")\n // remove the first empty string\n relativeNodeModuleDirectoryArray.shift()\n\n let i = relativeNodeModuleDirectoryArray.length\n while (i--) {\n candidates.push(\n `node_modules/${relativeNodeModuleDirectoryArray\n .slice(0, i + 1)\n .join(\"node_modules/\")}node_modules/`,\n )\n }\n\n return [...candidates, \"node_modules/\"]\n}\n", + "import { createDetailedMessage } from \"@jsenv/logger\"\nimport {\n resolveUrl,\n urlToRelativeUrl,\n assertAndNormalizeDirectoryUrl,\n urlToFileSystemPath,\n urlToBasename,\n readFile,\n} from \"@jsenv/util\"\nimport { optimizeImportMap } from \"../optimizeImportMap.js\"\nimport { resolvePackageMain } from \"./resolvePackageMain.js\"\nimport { visitPackageImportMap } from \"./visitPackageImportMap.js\"\nimport { visitPackageExports } from \"./visitPackageExports.js\"\nimport { createFindNodeModulePackage } from \"./node-module-resolution.js\"\n\nexport const getImportMapFromPackageFiles = async ({\n // nothing is actually listening for this cancellationToken for now\n // it's not very important but it would be better to register on it\n // an stops what we are doing if asked to do so\n // cancellationToken = createCancellationTokenForProcess(),\n logger,\n warn,\n projectDirectoryUrl,\n projectPackageDevDependenciesIncluded = process.env.NODE_ENV !== \"production\",\n packagesExportsPreference = [\"import\", \"browser\"],\n packagesExportsIncluded = true,\n packagesManualOverrides = {},\n packageIncludedPredicate = () => true,\n}) => {\n projectDirectoryUrl = assertAndNormalizeDirectoryUrl(projectDirectoryUrl)\n\n const projectPackageFileUrl = resolveUrl(\"./package.json\", projectDirectoryUrl)\n const findNodeModulePackage = createFindNodeModulePackage(packagesManualOverrides)\n\n const imports = {}\n const scopes = {}\n const addMapping = ({ scope, from, to }) => {\n if (scope) {\n // when a package says './' maps to './'\n // we must add something to say if we are already inside the package\n // no need to ensure leading slash are scoped to the package\n if (from === \"./\" && to === scope) {\n addMapping({\n scope,\n from: scope,\n to: scope,\n })\n const packageName = scope.slice(scope.lastIndexOf(\"node_modules/\") + `node_modules/`.length)\n addMapping({\n scope,\n from: packageName,\n to: scope,\n })\n }\n\n scopes[scope] = {\n ...(scopes[scope] || {}),\n [from]: to,\n }\n } else {\n // we could think it's useless to remap from with to\n // however it can be used to ensure a weaker remapping\n // does not win over this specific file or folder\n if (from === to) {\n /**\n * however remapping '/' to '/' is truly useless\n * moreover it would make wrapImportMap create something like\n * {\n * imports: {\n * \"/\": \"/.dist/best/\"\n * }\n * }\n * that would append the wrapped folder twice\n * */\n if (from === \"/\") return\n }\n imports[from] = to\n }\n }\n\n const seen = {}\n const markPackageAsSeen = (packageFileUrl, importerPackageFileUrl) => {\n if (packageFileUrl in seen) {\n seen[packageFileUrl].push(importerPackageFileUrl)\n } else {\n seen[packageFileUrl] = [importerPackageFileUrl]\n }\n }\n const packageIsSeen = (packageFileUrl, importerPackageFileUrl) => {\n return packageFileUrl in seen && seen[packageFileUrl].includes(importerPackageFileUrl)\n }\n\n const visit = async ({\n packageFileUrl,\n packageName,\n packageJsonObject,\n importerPackageFileUrl,\n importerPackageJsonObject,\n includeDevDependencies,\n }) => {\n if (!packageIncludedPredicate({ packageName, packageFileUrl, packageJsonObject })) {\n return\n }\n\n await visitDependencies({\n packageFileUrl,\n packageJsonObject,\n includeDevDependencies,\n })\n await visitPackage({\n packageFileUrl,\n packageName,\n packageJsonObject,\n importerPackageFileUrl,\n importerPackageJsonObject,\n })\n }\n\n const visitPackage = async ({\n packageFileUrl,\n packageName,\n packageJsonObject,\n importerPackageFileUrl,\n }) => {\n const packageInfo = computePackageInfo({\n packageFileUrl,\n packageName,\n importerPackageFileUrl,\n })\n\n await visitPackageMain({\n packageFileUrl,\n packageName,\n packageJsonObject,\n packageInfo,\n })\n\n const {\n importerIsRoot,\n importerRelativeUrl,\n packageIsRoot,\n packageDirectoryRelativeUrl,\n // packageDirectoryUrl,\n // packageDirectoryUrlExpected,\n } = packageInfo\n\n const addImportMapForPackage = (importMap) => {\n if (packageIsRoot) {\n const { imports = {}, scopes = {} } = importMap\n Object.keys(imports).forEach((from) => {\n addMapping({\n from,\n to: imports[from],\n })\n })\n Object.keys(scopes).forEach((scope) => {\n const scopeMappings = scopes[scope]\n Object.keys(scopeMappings).forEach((key) => {\n addMapping({\n scope,\n from: key,\n to: scopeMappings[key],\n })\n })\n })\n return\n }\n\n const { imports = {}, scopes = {} } = importMap\n const scope = `./${packageDirectoryRelativeUrl}`\n Object.keys(imports).forEach((from) => {\n const to = imports[from]\n const toMoved = moveMappingValue(to, packageFileUrl, projectDirectoryUrl)\n addMapping({\n scope,\n from,\n to: toMoved,\n })\n })\n Object.keys(scopes).forEach((scope) => {\n const scopeMappings = scopes[scope]\n const scopeMoved = moveMappingValue(scope, packageFileUrl, projectDirectoryUrl)\n Object.keys(scopeMappings).forEach((key) => {\n const to = scopeMappings[key]\n const toMoved = moveMappingValue(to, packageFileUrl, projectDirectoryUrl)\n addMapping({\n scope: scopeMoved,\n from: key,\n to: toMoved,\n })\n })\n })\n }\n\n const addMappingsForPackageAndImporter = (mappings) => {\n if (packageIsRoot) {\n Object.keys(mappings).forEach((from) => {\n const to = mappings[from]\n addMapping({\n from,\n to,\n })\n })\n return\n }\n\n if (importerIsRoot) {\n // own package mappings available to himself\n Object.keys(mappings).forEach((from) => {\n const to = mappings[from]\n addMapping({\n scope: `./${packageDirectoryRelativeUrl}`,\n from,\n to,\n })\n addMapping({ from, to })\n })\n\n // if importer is root no need to make package mappings available to the importer\n // because they are already on top level mappings\n return\n }\n\n Object.keys(mappings).forEach((from) => {\n const to = mappings[from]\n // own package exports available to himself\n addMapping({\n scope: `./${packageDirectoryRelativeUrl}`,\n from,\n to,\n })\n // now make package exports available to the importer\n // here if the importer is himself we could do stuff\n // we should even handle the case earlier to prevent top level remapping\n addMapping({\n scope: `./${importerRelativeUrl}`,\n from,\n to,\n })\n })\n }\n\n const importsFromPackageField = await visitPackageImportMap({\n warn,\n packageFileUrl,\n packageJsonObject,\n projectDirectoryUrl,\n })\n addImportMapForPackage(importsFromPackageField)\n\n if (packagesExportsIncluded && \"exports\" in packageJsonObject) {\n const mappingsFromPackageExports = {}\n visitPackageExports({\n warn,\n packageFileUrl,\n packageJsonObject,\n packageName,\n projectDirectoryUrl,\n packagesExportsPreference,\n onExport: ({ key, value }) => {\n const from = key\n const to = value\n\n if (from.indexOf(\"*\") === -1) {\n mappingsFromPackageExports[from] = to\n return\n }\n\n if (\n from.endsWith(\"/*\") &&\n to.endsWith(\"/*\") &&\n // ensure ends with '*' AND there is only one '*' occurence\n to.indexOf(\"*\") === to.length - 1\n ) {\n const fromWithouTrailingStar = from.slice(0, -1)\n const toWithoutTrailingStar = to.slice(0, -1)\n mappingsFromPackageExports[fromWithouTrailingStar] = toWithoutTrailingStar\n return\n }\n\n warn(\n createExportsWildcardIgnoredWarning({\n key,\n value,\n packageFileUrl,\n }),\n )\n },\n })\n addMappingsForPackageAndImporter(mappingsFromPackageExports)\n }\n }\n\n const visitPackageMain = async ({\n packageFileUrl,\n packageName,\n packageJsonObject,\n packageInfo: {\n importerIsRoot,\n importerRelativeUrl,\n packageDirectoryUrl,\n packageDirectoryUrlExpected,\n },\n }) => {\n const mainFileUrl = await resolvePackageMain({\n warn,\n packagesExportsPreference,\n packageFileUrl,\n packageJsonObject,\n })\n\n // it's possible to have no main\n // like { main: \"\" } in package.json\n // or a main that does not lead to an actual file\n if (mainFileUrl === null) {\n return\n }\n\n const mainFileRelativeUrl = urlToRelativeUrl(mainFileUrl, projectDirectoryUrl)\n const from = packageName\n const to = `./${mainFileRelativeUrl}`\n\n if (importerIsRoot) {\n addMapping({ from, to })\n } else {\n addMapping({\n scope: `./${importerRelativeUrl}`,\n from,\n to,\n })\n }\n if (packageDirectoryUrl !== packageDirectoryUrlExpected) {\n addMapping({\n scope: `./${importerRelativeUrl}`,\n from,\n to,\n })\n }\n }\n\n const visitDependencies = async ({\n packageFileUrl,\n packageJsonObject,\n includeDevDependencies,\n }) => {\n const dependencyMap = packageDependenciesFromPackageObject(packageJsonObject, {\n includeDevDependencies,\n })\n\n await Promise.all(\n Object.keys(dependencyMap).map(async (dependencyName) => {\n const dependencyInfo = dependencyMap[dependencyName]\n await visitDependency({\n packageFileUrl,\n packageJsonObject,\n dependencyName,\n dependencyInfo,\n })\n }),\n )\n }\n\n const visitDependency = async ({\n packageFileUrl,\n packageJsonObject,\n dependencyName,\n dependencyInfo,\n }) => {\n const dependencyData = await findDependency({\n packageFileUrl,\n dependencyName,\n })\n if (!dependencyData) {\n const cannotFindPackageWarning = createCannotFindPackageWarning({\n dependencyName,\n dependencyInfo,\n packageFileUrl,\n })\n if (dependencyInfo.isOptional) {\n logger.debug(cannotFindPackageWarning.message)\n } else {\n warn(cannotFindPackageWarning)\n }\n\n return\n }\n if (dependencyData.syntaxError) {\n return\n }\n\n const {\n packageFileUrl: dependencyPackageFileUrl,\n packageJsonObject: dependencyPackageJsonObject,\n } = dependencyData\n\n if (packageIsSeen(dependencyPackageFileUrl, packageFileUrl)) {\n return\n }\n markPackageAsSeen(dependencyPackageFileUrl, packageFileUrl)\n await visit({\n packageFileUrl: dependencyPackageFileUrl,\n packageName: dependencyName,\n packageJsonObject: dependencyPackageJsonObject,\n importerPackageFileUrl: packageFileUrl,\n importerPackageJsonObject: packageJsonObject,\n })\n }\n\n const computePackageInfo = ({ packageFileUrl, packageName, importerPackageFileUrl }) => {\n const importerIsRoot = importerPackageFileUrl === projectPackageFileUrl\n\n const importerPackageDirectoryUrl = resolveUrl(\"./\", importerPackageFileUrl)\n\n const importerRelativeUrl = urlToRelativeUrl(importerPackageDirectoryUrl, projectDirectoryUrl)\n\n const packageIsRoot = packageFileUrl === projectPackageFileUrl\n\n const packageDirectoryUrl = resolveUrl(\"./\", packageFileUrl)\n\n const packageDirectoryUrlExpected = `${importerPackageDirectoryUrl}node_modules/${packageName}/`\n\n const packageDirectoryRelativeUrl = urlToRelativeUrl(packageDirectoryUrl, projectDirectoryUrl)\n\n return {\n importerIsRoot,\n importerRelativeUrl,\n packageIsRoot,\n packageDirectoryUrl,\n packageDirectoryUrlExpected,\n packageDirectoryRelativeUrl,\n }\n }\n\n const dependenciesCache = {}\n const findDependency = ({ packageFileUrl, dependencyName }) => {\n if (packageFileUrl in dependenciesCache === false) {\n dependenciesCache[packageFileUrl] = {}\n }\n if (dependencyName in dependenciesCache[packageFileUrl]) {\n return dependenciesCache[packageFileUrl][dependencyName]\n }\n const dependencyPromise = findNodeModulePackage({\n projectDirectoryUrl,\n packageFileUrl,\n dependencyName,\n })\n dependenciesCache[packageFileUrl][dependencyName] = dependencyPromise\n return dependencyPromise\n }\n\n const projectPackageJsonObject = await readFile(projectPackageFileUrl, { as: \"json\" })\n const importerPackageFileUrl = projectPackageFileUrl\n markPackageAsSeen(projectPackageFileUrl, importerPackageFileUrl)\n\n const packageName = projectPackageJsonObject.name\n if (typeof packageName !== \"string\") {\n warn(\n createPackageNameMustBeAStringWarning({\n packageName,\n packageFileUrl: projectPackageFileUrl,\n }),\n )\n return {}\n }\n\n await visit({\n packageFileUrl: projectPackageFileUrl,\n packageName: projectPackageJsonObject.name,\n packageJsonObject: projectPackageJsonObject,\n importerPackageFileUrl,\n importerPackageJsonObject: null,\n includeDevDependencies: projectPackageDevDependenciesIncluded,\n })\n\n return optimizeImportMap({ imports, scopes })\n}\n\nconst packageDependenciesFromPackageObject = (packageObject, { includeDevDependencies }) => {\n const packageDependencies = {}\n\n const { dependencies = {} } = packageObject\n // https://npm.github.io/using-pkgs-docs/package-json/types/optionaldependencies.html\n const { optionalDependencies = {} } = packageObject\n Object.keys(dependencies).forEach((dependencyName) => {\n packageDependencies[dependencyName] = {\n type: \"dependency\",\n isOptional: dependencyName in optionalDependencies,\n versionPattern: dependencies[dependencyName],\n }\n })\n\n const { peerDependencies = {} } = packageObject\n const { peerDependenciesMeta = {} } = packageObject\n Object.keys(peerDependencies).forEach((dependencyName) => {\n packageDependencies[dependencyName] = {\n type: \"peerDependency\",\n versionPattern: peerDependencies[dependencyName],\n isOptional:\n dependencyName in peerDependenciesMeta && peerDependenciesMeta[dependencyName].optional,\n }\n })\n\n if (includeDevDependencies) {\n const { devDependencies = {} } = packageObject\n Object.keys(devDependencies).forEach((dependencyName) => {\n if (!packageDependencies.hasOwnProperty(dependencyName)) {\n packageDependencies[dependencyName] = {\n type: \"devDependency\",\n versionPattern: devDependencies[dependencyName],\n }\n }\n })\n }\n\n return packageDependencies\n}\n\nconst moveMappingValue = (address, from, to) => {\n const url = resolveUrl(address, from)\n const relativeUrl = urlToRelativeUrl(url, to)\n if (relativeUrl.startsWith(\"../\")) {\n return relativeUrl\n }\n if (relativeUrl.startsWith(\"./\")) {\n return relativeUrl\n }\n if (/^[a-zA-Z]{2,}:/.test(relativeUrl)) {\n // has sheme\n return relativeUrl\n }\n return `./${relativeUrl}`\n}\n\nconst createExportsWildcardIgnoredWarning = ({ key, value, packageFileUrl }) => {\n return {\n code: \"EXPORTS_WILDCARD\",\n message: `Ignoring export using \"*\" because it is not supported by importmap.\n--- key ---\n${key}\n--- value ---\n${value}\n--- package.json path ---\n${urlToFileSystemPath(packageFileUrl)}\n--- see also ---\nhttps://github.com/WICG/import-maps/issues/232`,\n }\n}\n\nconst createPackageNameMustBeAStringWarning = ({ packageName, packageFileUrl }) => {\n return {\n code: \"PACKAGE_NAME_MUST_BE_A_STRING\",\n message: `package name field must be a string\n--- package name field ---\n${packageName}\n--- package.json file path ---\n${packageFileUrl}`,\n }\n}\n\nconst createCannotFindPackageWarning = ({ dependencyName, dependencyInfo, packageFileUrl }) => {\n const dependencyIsOptional = dependencyInfo.isOptional\n const dependencyType = dependencyInfo.type\n const dependencyVersionPattern = dependencyInfo.versionPattern\n return {\n code: \"CANNOT_FIND_PACKAGE\",\n message: createDetailedMessage(\n dependencyIsOptional\n ? `cannot find an optional ${dependencyType}.`\n : `cannot find a ${dependencyType}.`,\n {\n [dependencyType]: `${dependencyName}@${dependencyVersionPattern}`,\n \"required by\": urlToFileSystemPath(packageFileUrl),\n },\n ),\n }\n}\n", + "import { sortImportMap, composeTwoImportMaps } from \"@jsenv/import-map\"\nimport { createLogger } from \"@jsenv/logger\"\nimport { getImportMapFromJsFiles } from \"./internal/from-js/getImportMapFromJsFiles.js\"\nimport { getImportMapFromPackageFiles } from \"./internal/from-package/getImportMapFromPackageFiles.js\"\n\nexport const getImportMapFromProjectFiles = async ({\n logLevel,\n projectDirectoryUrl,\n runtime = \"browser\",\n moduleFormat = \"esm\",\n dev = false,\n jsFiles = true,\n removeUnusedMappings = !dev,\n magicExtensions,\n onWarn = (warning, warn) => {\n warn(warning)\n },\n ...rest\n}) => {\n const packagesExportsPreference = [\n ...(moduleFormatPreferences[moduleFormat] || [moduleFormat]),\n ...(runtimeExportsPreferences[runtime] || [runtime]),\n ...(dev ? \"development\" : \"production\"),\n ]\n\n const logger = createLogger({ logLevel })\n const warn = (warning) => {\n onWarn(warning, () => {\n logger.warn(`\\n${warning.message}\\n`)\n })\n }\n\n // At this point, importmap is relative to the project directory url\n let importMapFromPackageFiles = await getImportMapFromPackageFiles({\n logger,\n warn,\n projectDirectoryUrl,\n packagesExportsPreference,\n projectPackageDevDependenciesIncluded: dev,\n ...rest,\n })\n importMapFromPackageFiles = sortImportMap(importMapFromPackageFiles)\n\n let importMapFromJsFiles = jsFiles\n ? await getImportMapFromJsFiles({\n logLevel,\n warn,\n importMap: importMapFromPackageFiles,\n removeUnusedMappings,\n projectDirectoryUrl,\n magicExtensions,\n packagesExportsPreference,\n runtime,\n })\n : {}\n importMapFromJsFiles = sortImportMap(importMapFromJsFiles)\n\n return sortImportMap(composeTwoImportMaps(importMapFromPackageFiles, importMapFromJsFiles))\n}\n\nconst runtimeExportsPreferences = {\n browser: [\"browser\"],\n node: [\"node\"],\n}\n\nconst moduleFormatPreferences = {\n esm: [\"import\"],\n cjs: [\"require\"],\n}\n", "import { assertAndNormalizeDirectoryUrl, resolveUrl, readFile } from \"@jsenv/util\"\nimport { moveImportMap, sortImportMap } from \"@jsenv/import-map\"\n\nexport const getImportMapFromFile = async ({ projectDirectoryUrl, importMapFileRelativeUrl }) => {\n projectDirectoryUrl = assertAndNormalizeDirectoryUrl(projectDirectoryUrl)\n\n const importmapFileUrl = resolveUrl(importMapFileRelativeUrl, projectDirectoryUrl)\n const importmap = await readFile(importmapFileUrl, { as: \"json\" })\n\n // ensure the importmap is now relative to the project directory url\n // we do that because writeImportMapFile expect all importmap\n // to be relative to the projectDirectoryUrl\n const importmapFakeRootUrl = resolveUrl(\"whatever.importmap\", projectDirectoryUrl)\n const importmapRelativeToProject = moveImportMap(\n importmap,\n importmapFileUrl,\n importmapFakeRootUrl,\n )\n\n return sortImportMap(importmapRelativeToProject)\n}\n", "export const importMapToVsCodeConfigPaths = ({ imports = {} }) => {\n const paths = {}\n\n Object.keys(imports).forEach((importKey) => {\n const importValue = imports[importKey]\n\n let key\n if (importKey.endsWith(\"/\")) {\n key = `${importKey}*`\n } else {\n key = importKey\n }\n\n const importValueArray = typeof importValue === \"string\" ? [importValue] : importValue\n const candidatesForPath = importValueArray.map((importValue) => {\n if (importValue.endsWith(\"/\")) {\n return `${importValue}*`\n }\n return importValue\n })\n\n if (key in paths) {\n paths[key] = [...paths[key], ...candidatesForPath]\n } else {\n paths[key] = candidatesForPath\n }\n })\n\n return paths\n}\n", "import {\n resolveUrl,\n urlToFileSystemPath,\n assertAndNormalizeDirectoryUrl,\n writeFile,\n} from \"@jsenv/util\"\nimport { composeTwoImportMaps } from \"@jsenv/import-map\"\nimport { importMapToVsCodeConfigPaths } from \"./internal/importMapToVsCodeConfigPaths.js\"\n\nexport const writeImportMapFile = async (\n importMapInputs = [],\n {\n projectDirectoryUrl,\n\n importMapFile = true, // in case someone wants the importmap but not write it on filesystem\n importMapFileRelativeUrl = \"./import-map.importmap\",\n importMapFileLog = true,\n\n jsConfigFile = false, // not yet documented, makes vscode aware of the import remapping\n jsConfigFileLog = true,\n jsConfigLeadingSlash = false,\n jsConfigBase = {},\n },\n) => {\n projectDirectoryUrl = assertAndNormalizeDirectoryUrl(projectDirectoryUrl)\n\n if (importMapInputs.length === 0) {\n console.warn(`importMapInputs is empty, the generated importmap will be empty`)\n }\n\n const importMaps = await Promise.all(importMapInputs)\n\n const importMap = importMaps.reduce((previous, current) => {\n return composeTwoImportMaps(previous, current)\n }, {})\n\n if (importMapFile) {\n const importMapFileUrl = resolveUrl(importMapFileRelativeUrl, projectDirectoryUrl)\n await writeFile(importMapFileUrl, JSON.stringify(importMap, null, \" \"))\n if (importMapFileLog) {\n console.info(`-> ${urlToFileSystemPath(importMapFileUrl)}`)\n }\n }\n if (jsConfigFile) {\n const jsConfigFileUrl = resolveUrl(\"./jsconfig.json\", projectDirectoryUrl)\n try {\n const jsConfig = {\n compilerOptions: {\n baseUrl: \".\",\n ...jsConfigBase,\n paths: {\n ...(jsConfigLeadingSlash ? { \"/*\": [\"./*\"] } : {}),\n ...importMapToVsCodeConfigPaths(importMap),\n },\n },\n }\n await writeFile(jsConfigFileUrl, JSON.stringify(jsConfig, null, \" \"))\n if (jsConfigFileLog) {\n console.info(`-> ${urlToFileSystemPath(jsConfigFileUrl)}`)\n }\n } catch (e) {\n if (e.code !== \"ENOENT\") {\n throw e\n }\n }\n }\n\n return importMap\n}\n" @@ -46,7 +46,8 @@ "names": [ "memoizeAsyncFunctionByUrl", "fn", - "cache", + "map", + "WeakMap", "memoizeAsyncFunction", "getMemoryEntryFromArguments", "url", @@ -62,14 +63,15 @@ "args", "memoryEntry", "promiseFromMemory", - "_resolve", - "_reject", - "Promise", "resolve", "reject", + "createControllablePromise", "value", "error", "e", + "Promise", + "res", + "rej", "filenameContainsBackSlashes", "__filename", "indexOf", @@ -87,6 +89,7 @@ "ranges", "jsx", "typescript", + "endsWith", "flow", "options", "undefined", @@ -147,7 +150,6 @@ "Math", "floor", "ceil", - "map", "lineSource", "index", "lineNumber", @@ -183,7 +185,6 @@ "isFile", "isDirectory", "indexFileSuffix", - "endsWith", "indexFileUrl", "extensionLeadingToAFile", "findExtensionLeadingToFile", @@ -238,6 +239,7 @@ "formatAutoMappingSpecifierWarning", "closestPackageDirectoryUrl", "closestPackageObject", + "visitFileContent", "readFileContent", "all", "Object", @@ -380,8 +382,6 @@ "packageIncludedPredicate", "assertAndNormalizeDirectoryUrl", "findNodeModulePackage", - "addTopLevelImportMapping", - "addScopedImportMapping", "seen", "markPackageAsSeen", "importerPackageFileUrl", @@ -422,7 +422,6 @@ "dependencyPackageFileUrl", "dependencyPackageJsonObject", "importerPackageDirectoryUrl", - "urlToBasename", "dependenciesCache", "dependencyPromise", "projectPackageJsonObject", @@ -487,5 +486,5 @@ "compilerOptions", "baseUrl" ], - "mappings": ";;;;;;;;;;AAAO,MAAMA,yBAAyB,GAAIC,EAAD,IAAQ;AAC/C,QAAMC,KAAK,GAAG,EAAd;AACA,SAAOC,oBAAoB,CAACF,EAAD,EAAK;AAC9BG,IAAAA,2BAA2B,EAAE,CAAC,CAACC,GAAD,CAAD,KAAW;AACtC,aAAO;AACLC,QAAAA,GAAG,EAAE,MAAM;AACT,iBAAOJ,KAAK,CAACG,GAAD,CAAZ;AACD,SAHI;A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E,oBAAM,CAAC,KAAD;AAAR,aAAH,GAAuB,EAA/C,CADK;AAEL,eAAGZ,4BAA4B,CAAC/P,WAAD;AAF1B;AAHQ;AADF,OAAjB;AAUA,YAAMkR,cAAS,CAACE,eAAD,EAAkBjN,IAAI,CAACC,SAAL,CAAeiN,QAAf,EAAyB,IAAzB,EAA+B,IAA/B,CAAlB,CAAf;;AACA,UAAIX,eAAJ,EAAqB;AACnBjH,QAAAA,OAAO,CAAC0H,IAAR,CAAc,MAAK9X,wBAAmB,CAAC+X,eAAD,CAAkB,EAAxD;AACD;AACF,KAfD,CAeE,OAAO7Z,CAAP,EAAU;AACV,UAAIA,CAAC,CAACqM,IAAF,KAAW,QAAf,EAAyB;AACvB,cAAMrM,CAAN;AACD;AACF;AACF;;AAED,SAAOyI,WAAP;AACD;;;;;;" } \ No newline at end of file diff --git a/package.json b/package.json index 431f85bb..a761b14b 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@jsenv/node-module-import-map", - "version": "13.0.0-alpha.2", + "version": "13.0.0-alpha.3", "description": "Generate importmap for node_modules.", "license": "MIT", "repository": { diff --git a/src/internal/from-js/getImportMapFromJsFiles.js b/src/internal/from-js/getImportMapFromJsFiles.js index 29ba3e6f..90fe36dc 100644 --- a/src/internal/from-js/getImportMapFromJsFiles.js +++ b/src/internal/from-js/getImportMapFromJsFiles.js @@ -124,15 +124,19 @@ export const getImportMapFromJsFiles = async ({ ) } - const fileContent = await readFileContent(fileUrlOnFileSystem) - const specifiers = await parseSpecifiersFromFile(fileUrlOnFileSystem, { fileContent }) + await visitFileContent(fileUrlOnFileSystem) + } + + const visitFileContent = memoizeAsyncFunctionByUrl(async (fileUrl) => { + const fileContent = await readFileContent(fileUrl) + const specifiers = await parseSpecifiersFromFile(fileUrl, { fileContent }) await Promise.all( Object.keys(specifiers).map(async (specifier) => { const specifierInfo = specifiers[specifier] - await visitFileMemoized(specifier, fileUrlOnFileSystem, { + await visitFileMemoized(specifier, fileUrl, { importedBy: showSource({ - url: fileUrlOnFileSystem, + url: fileUrl, line: specifierInfo.line, column: specifierInfo.column, source: fileContent, @@ -140,7 +144,7 @@ export const getImportMapFromJsFiles = async ({ }) }), ) - } + }) const visitFileMemoized = memoizeAsyncFunctionBySpecifierAndImporter(visitFile) const readFileContent = memoizeAsyncFunctionByUrl((fileUrl) => { diff --git a/src/internal/from-js/parseSpecifiersFromFile.js b/src/internal/from-js/parseSpecifiersFromFile.js index 9b722e3e..d6aadb53 100644 --- a/src/internal/from-js/parseSpecifiersFromFile.js +++ b/src/internal/from-js/parseSpecifiersFromFile.js @@ -15,7 +15,7 @@ export const parseSpecifiersFromFile = async ( allowAwaitOutsideFunction = true, ranges = true, jsx = true, - typescript = true, + typescript = fileUrl.endsWith(".ts") || fileUrl.endsWith(".tsx"), flow = false, ...options } = {}, @@ -34,7 +34,7 @@ export const parseSpecifiersFromFile = async ( "exportDefaultFrom", ...(jsx ? ["jsx"] : []), ...(typescript ? ["typescript"] : []), - ...(flow ? ["jsx"] : []), + ...(flow ? ["flow"] : []), ], ...options, }) diff --git a/src/internal/memoizeAsyncFunction.js b/src/internal/memoizeAsyncFunction.js index 5e5a46bc..8017f4ce 100644 --- a/src/internal/memoizeAsyncFunction.js +++ b/src/internal/memoizeAsyncFunction.js @@ -1,16 +1,16 @@ export const memoizeAsyncFunctionByUrl = (fn) => { - const cache = {} + const map = new WeakMap() return memoizeAsyncFunction(fn, { getMemoryEntryFromArguments: ([url]) => { return { get: () => { - return cache[url] + return map.get(url) }, set: (promise) => { - cache[url] = promise + map.set(url, promise) }, delete: () => { - delete cache[url] + map.delete(url) }, } }, @@ -54,12 +54,7 @@ const memoizeAsyncFunction = (fn, { getMemoryEntryFromArguments }) => { if (promiseFromMemory) { return promiseFromMemory } - let _resolve - let _reject - const promise = new Promise((resolve, reject) => { - _resolve = resolve - _reject = reject - }) + const { promise, resolve, reject } = createControllablePromise() memoryEntry.set(promise) let value let error @@ -72,10 +67,20 @@ const memoizeAsyncFunction = (fn, { getMemoryEntryFromArguments }) => { memoryEntry.delete() } if (error) { - _reject(error) + reject(error) } else { - _resolve(value) + resolve(value) } return promise } } + +const createControllablePromise = () => { + let resolve + let reject + const promise = new Promise((res, rej) => { + resolve = res + reject = rej + }) + return { promise, resolve, reject } +} From 5b966a82f36ec69567a8114c791ede9560331078 Mon Sep 17 00:00:00 2001 From: Damien Maillard Date: Fri, 12 Mar 2021 15:51:45 +0100 Subject: [PATCH 31/36] fix some mistakes --- src/getImportMapFromProjectFiles.js | 29 +++++++++---------- .../from-js/getImportMapFromJsFiles.js | 9 ++++-- .../getImportMapFromPackageFiles.js | 1 - src/internal/memoizeAsyncFunction.js | 8 ++--- 4 files changed, 25 insertions(+), 22 deletions(-) diff --git a/src/getImportMapFromProjectFiles.js b/src/getImportMapFromProjectFiles.js index d60e6488..1cb509ab 100644 --- a/src/getImportMapFromProjectFiles.js +++ b/src/getImportMapFromProjectFiles.js @@ -1,4 +1,4 @@ -import { sortImportMap, composeTwoImportMaps } from "@jsenv/import-map" +import { sortImportMap } from "@jsenv/import-map" import { createLogger } from "@jsenv/logger" import { getImportMapFromJsFiles } from "./internal/from-js/getImportMapFromJsFiles.js" import { getImportMapFromPackageFiles } from "./internal/from-package/getImportMapFromPackageFiles.js" @@ -40,22 +40,21 @@ export const getImportMapFromProjectFiles = async ({ ...rest, }) importMapFromPackageFiles = sortImportMap(importMapFromPackageFiles) + if (!jsFiles) { + return importMapFromPackageFiles + } - let importMapFromJsFiles = jsFiles - ? await getImportMapFromJsFiles({ - logLevel, - warn, - importMap: importMapFromPackageFiles, - removeUnusedMappings, - projectDirectoryUrl, - magicExtensions, - packagesExportsPreference, - runtime, - }) - : {} + let importMapFromJsFiles = await getImportMapFromJsFiles({ + warn, + importMap: importMapFromPackageFiles, + removeUnusedMappings, + projectDirectoryUrl, + magicExtensions, + packagesExportsPreference, + runtime, + }) importMapFromJsFiles = sortImportMap(importMapFromJsFiles) - - return sortImportMap(composeTwoImportMaps(importMapFromPackageFiles, importMapFromJsFiles)) + return importMapFromJsFiles } const runtimeExportsPreferences = { diff --git a/src/internal/from-js/getImportMapFromJsFiles.js b/src/internal/from-js/getImportMapFromJsFiles.js index 90fe36dc..2208b8fc 100644 --- a/src/internal/from-js/getImportMapFromJsFiles.js +++ b/src/internal/from-js/getImportMapFromJsFiles.js @@ -1,6 +1,11 @@ import { createDetailedMessage } from "@jsenv/logger" import { resolveUrl, readFile, urlToExtension, urlToRelativeUrl } from "@jsenv/util" -import { normalizeImportMap, resolveImport } from "@jsenv/import-map" +import { + normalizeImportMap, + resolveImport, + sortImportMap, + composeTwoImportMaps, +} from "@jsenv/import-map" import { memoizeAsyncFunctionByUrl, memoizeAsyncFunctionBySpecifierAndImporter, @@ -178,7 +183,7 @@ export const getImportMapFromJsFiles = async ({ } } - return { imports, scopes } + return sortImportMap(composeTwoImportMaps(importMap, { imports, scopes })) } const packageDirectoryUrlFromUrl = (url, projectDirectoryUrl) => { diff --git a/src/internal/from-package/getImportMapFromPackageFiles.js b/src/internal/from-package/getImportMapFromPackageFiles.js index 3c3530b1..f9031958 100644 --- a/src/internal/from-package/getImportMapFromPackageFiles.js +++ b/src/internal/from-package/getImportMapFromPackageFiles.js @@ -4,7 +4,6 @@ import { urlToRelativeUrl, assertAndNormalizeDirectoryUrl, urlToFileSystemPath, - urlToBasename, readFile, } from "@jsenv/util" import { optimizeImportMap } from "../optimizeImportMap.js" diff --git a/src/internal/memoizeAsyncFunction.js b/src/internal/memoizeAsyncFunction.js index 8017f4ce..5f717a7c 100644 --- a/src/internal/memoizeAsyncFunction.js +++ b/src/internal/memoizeAsyncFunction.js @@ -1,16 +1,16 @@ export const memoizeAsyncFunctionByUrl = (fn) => { - const map = new WeakMap() + const cache = {} return memoizeAsyncFunction(fn, { getMemoryEntryFromArguments: ([url]) => { return { get: () => { - return map.get(url) + return cache[url] }, set: (promise) => { - map.set(url, promise) + cache[url] = promise }, delete: () => { - map.delete(url) + delete cache[url] }, } }, From 204d7f37b599d0610b3b01a9ad8167f115524834 Mon Sep 17 00:00:00 2001 From: Damien Maillard Date: Fri, 12 Mar 2021 16:16:14 +0100 Subject: [PATCH 32/36] handle circular dependencies in source files --- .../from-js/getImportMapFromJsFiles.js | 155 ++++++++++-------- src/internal/memoizeAsyncFunction.js | 6 +- .../js-import-circular-deep.test.js | 27 +++ .../js-import-circular-deep/root/a.js | 1 + .../js-import-circular-deep/root/b.js | 1 + .../js-import-circular-deep/root/index.js | 1 + .../js-import-circular-deep/root/package.json | 3 + .../js-import-circular.test.js | 27 +++ .../js-import-circular/root/a.js | 1 + .../js-import-circular/root/index.js | 1 + .../js-import-circular/root/package.json | 3 + 11 files changed, 154 insertions(+), 72 deletions(-) create mode 100644 test/getImportMapFromProjectFiles/js-import-circular-deep/js-import-circular-deep.test.js create mode 100644 test/getImportMapFromProjectFiles/js-import-circular-deep/root/a.js create mode 100644 test/getImportMapFromProjectFiles/js-import-circular-deep/root/b.js create mode 100644 test/getImportMapFromProjectFiles/js-import-circular-deep/root/index.js create mode 100644 test/getImportMapFromProjectFiles/js-import-circular-deep/root/package.json create mode 100644 test/getImportMapFromProjectFiles/js-import-circular/js-import-circular.test.js create mode 100644 test/getImportMapFromProjectFiles/js-import-circular/root/a.js create mode 100644 test/getImportMapFromProjectFiles/js-import-circular/root/index.js create mode 100644 test/getImportMapFromProjectFiles/js-import-circular/root/package.json diff --git a/src/internal/from-js/getImportMapFromJsFiles.js b/src/internal/from-js/getImportMapFromJsFiles.js index 2208b8fc..c38884c2 100644 --- a/src/internal/from-js/getImportMapFromJsFiles.js +++ b/src/internal/from-js/getImportMapFromJsFiles.js @@ -69,77 +69,79 @@ export const getImportMapFromJsFiles = async ({ }) } - const visitFile = async (specifier, importer, { importedBy }) => { - let fileUrl - let gotBareSpecifierError = false + const resolveFileSystemUrl = memoizeAsyncFunctionBySpecifierAndImporter( + async (specifier, importer, { importedBy }) => { + let fileUrl + let gotBareSpecifierError = false - try { - fileUrl = trackAndResolveImport(specifier, importer) - } catch (e) { - if (e !== BARE_SPECIFIER_ERROR) { - throw e + try { + fileUrl = trackAndResolveImport(specifier, importer) + } catch (e) { + if (e !== BARE_SPECIFIER_ERROR) { + throw e + } + if (importer === projectPackageFileUrl) { + // cannot find package main file (package.main is "" for instance) + // we can't discover main file and parse dependencies + return null + } + gotBareSpecifierError = true + fileUrl = resolveUrl(specifier, importer) } - if (importer === projectPackageFileUrl) { - // cannot find package main file (package.main is "" for instance) - // we can't discover main file and parse dependencies - return - } - gotBareSpecifierError = true - fileUrl = resolveUrl(specifier, importer) - } - const fileUrlOnFileSystem = await resolveFile(fileUrl, { - magicExtensions: magicExtensionWithImporterExtension(magicExtensions, importer), - }) + const fileUrlOnFileSystem = await resolveFile(fileUrl, { + magicExtensions: magicExtensionWithImporterExtension(magicExtensions, importer), + }) - if (!fileUrlOnFileSystem) { - warn( - createFileNotFoundWarning({ - specifier, - importedBy, - fileUrl, - magicExtensions, - }), - ) - return - } + if (!fileUrlOnFileSystem) { + warn( + createFileNotFoundWarning({ + specifier, + importedBy, + fileUrl, + magicExtensions, + }), + ) + return null + } - const needsAutoMapping = fileUrlOnFileSystem !== fileUrl || gotBareSpecifierError - if (needsAutoMapping) { - const packageDirectoryUrl = packageDirectoryUrlFromUrl(fileUrl, projectDirectoryUrl) - const packageFileUrl = resolveUrl("package.json", packageDirectoryUrl) - const autoMapping = { - scope: - packageFileUrl === projectPackageFileUrl - ? undefined - : `./${urlToRelativeUrl(packageDirectoryUrl, projectDirectoryUrl)}`, - from: specifier, - to: `./${urlToRelativeUrl(fileUrlOnFileSystem, projectDirectoryUrl)}`, + const needsAutoMapping = fileUrlOnFileSystem !== fileUrl || gotBareSpecifierError + if (needsAutoMapping) { + const packageDirectoryUrl = packageDirectoryUrlFromUrl(fileUrl, projectDirectoryUrl) + const packageFileUrl = resolveUrl("package.json", packageDirectoryUrl) + const autoMapping = { + scope: + packageFileUrl === projectPackageFileUrl + ? undefined + : `./${urlToRelativeUrl(packageDirectoryUrl, projectDirectoryUrl)}`, + from: specifier, + to: `./${urlToRelativeUrl(fileUrlOnFileSystem, projectDirectoryUrl)}`, + } + addMapping(autoMapping) + markMappingAsUsed(autoMapping) + warn( + formatAutoMappingSpecifierWarning({ + specifier, + importedBy, + autoMapping, + closestPackageDirectoryUrl: packageDirectoryUrl, + closestPackageObject: await readFile(packageFileUrl, { as: "json" }), + }), + ) } - addMapping(autoMapping) - markMappingAsUsed(autoMapping) - warn( - formatAutoMappingSpecifierWarning({ - specifier, - importedBy, - autoMapping, - closestPackageDirectoryUrl: packageDirectoryUrl, - closestPackageObject: await readFile(packageFileUrl, { as: "json" }), - }), - ) - } - await visitFileContent(fileUrlOnFileSystem) - } + return fileUrlOnFileSystem + }, + ) - const visitFileContent = memoizeAsyncFunctionByUrl(async (fileUrl) => { - const fileContent = await readFileContent(fileUrl) + const visitFile = memoizeAsyncFunctionByUrl(async (fileUrl) => { + const fileContent = await readFile(fileUrl, { as: "string" }) const specifiers = await parseSpecifiersFromFile(fileUrl, { fileContent }) - await Promise.all( + const dependencies = await Promise.all( Object.keys(specifiers).map(async (specifier) => { const specifierInfo = specifiers[specifier] - await visitFileMemoized(specifier, fileUrl, { + const dependencyUrlOnFileSystem = await resolveFileSystemUrl(specifier, fileUrl, { importedBy: showSource({ url: fileUrl, line: specifierInfo.line, @@ -147,21 +149,32 @@ export const getImportMapFromJsFiles = async ({ source: fileContent, }), }) + return dependencyUrlOnFileSystem + }), + ) + const dependenciesToVisit = dependencies.filter((dependency) => { + return dependency && !visitFile.isInMemory(dependency) + }) + await Promise.all( + dependenciesToVisit.map((dependency) => { + return visitFile(dependency) }), ) - }) - const visitFileMemoized = memoizeAsyncFunctionBySpecifierAndImporter(visitFile) - - const readFileContent = memoizeAsyncFunctionByUrl((fileUrl) => { - return readFile(fileUrl, { as: "string" }) }) const projectPackageObject = await readFile(projectPackageFileUrl, { as: "json" }) - await visitFileMemoized(projectPackageObject.name, projectPackageFileUrl, { - importedBy: projectPackageObject.exports - ? `${projectPackageFileUrl}#exports` - : `${projectPackageFileUrl}`, - }) + const projectMainFileUrlOnFileSystem = await resolveFileSystemUrl( + projectPackageObject.name, + projectPackageFileUrl, + { + importedBy: projectPackageObject.exports + ? `${projectPackageFileUrl}#exports` + : `${projectPackageFileUrl}`, + }, + ) + if (projectMainFileUrlOnFileSystem) { + await visitFile(projectMainFileUrlOnFileSystem) + } if (removeUnusedMappings) { const importsUsed = {} @@ -177,10 +190,10 @@ export const getImportMapFromJsFiles = async ({ }) scopesUsed[scope] = scopedMappings }) - return { + return sortImportMap({ imports: importsUsed, scopes: scopesUsed, - } + }) } return sortImportMap(composeTwoImportMaps(importMap, { imports, scopes })) diff --git a/src/internal/memoizeAsyncFunction.js b/src/internal/memoizeAsyncFunction.js index 5f717a7c..70c38ef1 100644 --- a/src/internal/memoizeAsyncFunction.js +++ b/src/internal/memoizeAsyncFunction.js @@ -48,7 +48,7 @@ export const memoizeAsyncFunctionBySpecifierAndImporter = (fn) => { } const memoizeAsyncFunction = (fn, { getMemoryEntryFromArguments }) => { - return async (...args) => { + const memoized = async (...args) => { const memoryEntry = getMemoryEntryFromArguments(args) const promiseFromMemory = memoryEntry.get() if (promiseFromMemory) { @@ -73,6 +73,10 @@ const memoizeAsyncFunction = (fn, { getMemoryEntryFromArguments }) => { } return promise } + memoized.isInMemory = (...args) => { + return Boolean(getMemoryEntryFromArguments(args).get()) + } + return memoized } const createControllablePromise = () => { diff --git a/test/getImportMapFromProjectFiles/js-import-circular-deep/js-import-circular-deep.test.js b/test/getImportMapFromProjectFiles/js-import-circular-deep/js-import-circular-deep.test.js new file mode 100644 index 00000000..ce4fe786 --- /dev/null +++ b/test/getImportMapFromProjectFiles/js-import-circular-deep/js-import-circular-deep.test.js @@ -0,0 +1,27 @@ +import { assert } from "@jsenv/assert" +import { resolveUrl } from "@jsenv/util" +import { getImportMapFromProjectFiles } from "@jsenv/node-module-import-map" + +const testDirectoryUrl = resolveUrl("./root/", import.meta.url) + +const warnings = [] +const importmap = await getImportMapFromProjectFiles({ + projectDirectoryUrl: testDirectoryUrl, + onWarn: (warning) => { + warnings.push(warning) + }, +}) +const actual = { + warnings, + importmap, +} +const expected = { + warnings: [], + importmap: { + imports: { + root: "./index.js", + }, + scopes: {}, + }, +} +assert({ actual, expected }) diff --git a/test/getImportMapFromProjectFiles/js-import-circular-deep/root/a.js b/test/getImportMapFromProjectFiles/js-import-circular-deep/root/a.js new file mode 100644 index 00000000..a1132051 --- /dev/null +++ b/test/getImportMapFromProjectFiles/js-import-circular-deep/root/a.js @@ -0,0 +1 @@ +import "./b.js" diff --git a/test/getImportMapFromProjectFiles/js-import-circular-deep/root/b.js b/test/getImportMapFromProjectFiles/js-import-circular-deep/root/b.js new file mode 100644 index 00000000..83988e1a --- /dev/null +++ b/test/getImportMapFromProjectFiles/js-import-circular-deep/root/b.js @@ -0,0 +1 @@ +import "./a.js" diff --git a/test/getImportMapFromProjectFiles/js-import-circular-deep/root/index.js b/test/getImportMapFromProjectFiles/js-import-circular-deep/root/index.js new file mode 100644 index 00000000..83988e1a --- /dev/null +++ b/test/getImportMapFromProjectFiles/js-import-circular-deep/root/index.js @@ -0,0 +1 @@ +import "./a.js" diff --git a/test/getImportMapFromProjectFiles/js-import-circular-deep/root/package.json b/test/getImportMapFromProjectFiles/js-import-circular-deep/root/package.json new file mode 100644 index 00000000..7636edf1 --- /dev/null +++ b/test/getImportMapFromProjectFiles/js-import-circular-deep/root/package.json @@ -0,0 +1,3 @@ +{ + "name": "root" +} diff --git a/test/getImportMapFromProjectFiles/js-import-circular/js-import-circular.test.js b/test/getImportMapFromProjectFiles/js-import-circular/js-import-circular.test.js new file mode 100644 index 00000000..ce4fe786 --- /dev/null +++ b/test/getImportMapFromProjectFiles/js-import-circular/js-import-circular.test.js @@ -0,0 +1,27 @@ +import { assert } from "@jsenv/assert" +import { resolveUrl } from "@jsenv/util" +import { getImportMapFromProjectFiles } from "@jsenv/node-module-import-map" + +const testDirectoryUrl = resolveUrl("./root/", import.meta.url) + +const warnings = [] +const importmap = await getImportMapFromProjectFiles({ + projectDirectoryUrl: testDirectoryUrl, + onWarn: (warning) => { + warnings.push(warning) + }, +}) +const actual = { + warnings, + importmap, +} +const expected = { + warnings: [], + importmap: { + imports: { + root: "./index.js", + }, + scopes: {}, + }, +} +assert({ actual, expected }) diff --git a/test/getImportMapFromProjectFiles/js-import-circular/root/a.js b/test/getImportMapFromProjectFiles/js-import-circular/root/a.js new file mode 100644 index 00000000..84c59f01 --- /dev/null +++ b/test/getImportMapFromProjectFiles/js-import-circular/root/a.js @@ -0,0 +1 @@ +import "./index.js" diff --git a/test/getImportMapFromProjectFiles/js-import-circular/root/index.js b/test/getImportMapFromProjectFiles/js-import-circular/root/index.js new file mode 100644 index 00000000..83988e1a --- /dev/null +++ b/test/getImportMapFromProjectFiles/js-import-circular/root/index.js @@ -0,0 +1 @@ +import "./a.js" diff --git a/test/getImportMapFromProjectFiles/js-import-circular/root/package.json b/test/getImportMapFromProjectFiles/js-import-circular/root/package.json new file mode 100644 index 00000000..7636edf1 --- /dev/null +++ b/test/getImportMapFromProjectFiles/js-import-circular/root/package.json @@ -0,0 +1,3 @@ +{ + "name": "root" +} From dd31acbbcab9e2277380b29d8689c8579fc38511 Mon Sep 17 00:00:00 2001 From: Damien Maillard Date: Fri, 12 Mar 2021 16:38:33 +0100 Subject: [PATCH 33/36] update tests --- src/internal/from-js/getImportMapFromJsFiles.js | 5 +++++ test/getImportMapFromProjectFiles/core/basic/root/index.js | 5 +++++ .../core/basic/root/node_modules/@dmail/yo/index.js | 1 + .../core/basic/root/node_modules/bar/bar.js | 1 + .../core/basic/root/node_modules/foo/foo.js | 3 +++ .../basic/root/node_modules/foo/node_modules/bar/index.js | 1 + .../core/issue-20/issue-20.test.js | 1 + .../getImportMapFromProjectFiles/core/issue-20/root/index.js | 2 ++ .../core/issue-20/root/node_modules/lume/lume.js | 1 + .../core/issue-20/root/package.json | 2 -- test/getImportMapFromProjectFiles/core/shared/root/index.js | 4 ++++ .../core/shared/root/node_modules/foo/foo.js | 1 + .../core/shared/root/package.json | 1 - test/getImportMapFromProjectFiles/core/shared/shared.test.js | 1 + 14 files changed, 26 insertions(+), 3 deletions(-) create mode 100644 test/getImportMapFromProjectFiles/core/issue-20/root/index.js create mode 100644 test/getImportMapFromProjectFiles/core/shared/root/index.js diff --git a/src/internal/from-js/getImportMapFromJsFiles.js b/src/internal/from-js/getImportMapFromJsFiles.js index c38884c2..77c93cdb 100644 --- a/src/internal/from-js/getImportMapFromJsFiles.js +++ b/src/internal/from-js/getImportMapFromJsFiles.js @@ -59,6 +59,11 @@ export const getImportMapFromJsFiles = async ({ importMap: importMapNormalized, defaultExtension: false, onImportMapping: ({ scope, from }) => { + if (scope) { + // make scope relative again + scope = `./${urlToRelativeUrl(scope, projectDirectoryUrl)}` + } + markMappingAsUsed({ scope, from, diff --git a/test/getImportMapFromProjectFiles/core/basic/root/index.js b/test/getImportMapFromProjectFiles/core/basic/root/index.js index e69de29b..ef63967e 100644 --- a/test/getImportMapFromProjectFiles/core/basic/root/index.js +++ b/test/getImportMapFromProjectFiles/core/basic/root/index.js @@ -0,0 +1,5 @@ +/* eslint-disable import/no-unresolved */ +import "bar" +import "foo" +import "@dmail/yo" +import "root/index.js" diff --git a/test/getImportMapFromProjectFiles/core/basic/root/node_modules/@dmail/yo/index.js b/test/getImportMapFromProjectFiles/core/basic/root/node_modules/@dmail/yo/index.js index e69de29b..7ebfe3e4 100644 --- a/test/getImportMapFromProjectFiles/core/basic/root/node_modules/@dmail/yo/index.js +++ b/test/getImportMapFromProjectFiles/core/basic/root/node_modules/@dmail/yo/index.js @@ -0,0 +1 @@ +import "@dmail/yo/index.js" \ No newline at end of file diff --git a/test/getImportMapFromProjectFiles/core/basic/root/node_modules/bar/bar.js b/test/getImportMapFromProjectFiles/core/basic/root/node_modules/bar/bar.js index e69de29b..1ec404b7 100644 --- a/test/getImportMapFromProjectFiles/core/basic/root/node_modules/bar/bar.js +++ b/test/getImportMapFromProjectFiles/core/basic/root/node_modules/bar/bar.js @@ -0,0 +1 @@ +import "bar/bar.js" \ No newline at end of file diff --git a/test/getImportMapFromProjectFiles/core/basic/root/node_modules/foo/foo.js b/test/getImportMapFromProjectFiles/core/basic/root/node_modules/foo/foo.js index e69de29b..304235f9 100644 --- a/test/getImportMapFromProjectFiles/core/basic/root/node_modules/foo/foo.js +++ b/test/getImportMapFromProjectFiles/core/basic/root/node_modules/foo/foo.js @@ -0,0 +1,3 @@ +import "bar" +import "bar/index.js" +import 'foo/foo.js' \ No newline at end of file diff --git a/test/getImportMapFromProjectFiles/core/basic/root/node_modules/foo/node_modules/bar/index.js b/test/getImportMapFromProjectFiles/core/basic/root/node_modules/foo/node_modules/bar/index.js index e69de29b..854dd54f 100644 --- a/test/getImportMapFromProjectFiles/core/basic/root/node_modules/foo/node_modules/bar/index.js +++ b/test/getImportMapFromProjectFiles/core/basic/root/node_modules/foo/node_modules/bar/index.js @@ -0,0 +1 @@ +import "bar/index.js" \ No newline at end of file diff --git a/test/getImportMapFromProjectFiles/core/issue-20/issue-20.test.js b/test/getImportMapFromProjectFiles/core/issue-20/issue-20.test.js index 90cc9b39..4ded8787 100644 --- a/test/getImportMapFromProjectFiles/core/issue-20/issue-20.test.js +++ b/test/getImportMapFromProjectFiles/core/issue-20/issue-20.test.js @@ -13,6 +13,7 @@ const importMap = await getImportMapFromProjectFiles({ const expected = { imports: { lume: "./node_modules/lume/lume.js", + root: "./index.js", }, scopes: { "./node_modules/lume/": { diff --git a/test/getImportMapFromProjectFiles/core/issue-20/root/index.js b/test/getImportMapFromProjectFiles/core/issue-20/root/index.js new file mode 100644 index 00000000..146938d8 --- /dev/null +++ b/test/getImportMapFromProjectFiles/core/issue-20/root/index.js @@ -0,0 +1,2 @@ +/* eslint-disable import/no-unresolved */ +import "lume" diff --git a/test/getImportMapFromProjectFiles/core/issue-20/root/node_modules/lume/lume.js b/test/getImportMapFromProjectFiles/core/issue-20/root/node_modules/lume/lume.js index e69de29b..bcba9a75 100644 --- a/test/getImportMapFromProjectFiles/core/issue-20/root/node_modules/lume/lume.js +++ b/test/getImportMapFromProjectFiles/core/issue-20/root/node_modules/lume/lume.js @@ -0,0 +1 @@ +import "lowclass" \ No newline at end of file diff --git a/test/getImportMapFromProjectFiles/core/issue-20/root/package.json b/test/getImportMapFromProjectFiles/core/issue-20/root/package.json index b8dbdd33..6b256214 100644 --- a/test/getImportMapFromProjectFiles/core/issue-20/root/package.json +++ b/test/getImportMapFromProjectFiles/core/issue-20/root/package.json @@ -1,7 +1,5 @@ { "name": "root", - "type": "module", - "main": "", "dependencies": { "lume": "*" } diff --git a/test/getImportMapFromProjectFiles/core/shared/root/index.js b/test/getImportMapFromProjectFiles/core/shared/root/index.js new file mode 100644 index 00000000..8be0caa9 --- /dev/null +++ b/test/getImportMapFromProjectFiles/core/shared/root/index.js @@ -0,0 +1,4 @@ +/* eslint-disable import/no-unresolved */ +import "bar" +import "bar/bar.js" +import "foo" diff --git a/test/getImportMapFromProjectFiles/core/shared/root/node_modules/foo/foo.js b/test/getImportMapFromProjectFiles/core/shared/root/node_modules/foo/foo.js index e69de29b..e5bfaa3f 100644 --- a/test/getImportMapFromProjectFiles/core/shared/root/node_modules/foo/foo.js +++ b/test/getImportMapFromProjectFiles/core/shared/root/node_modules/foo/foo.js @@ -0,0 +1 @@ +import 'bar' \ No newline at end of file diff --git a/test/getImportMapFromProjectFiles/core/shared/root/package.json b/test/getImportMapFromProjectFiles/core/shared/root/package.json index fe3b1db2..cccc7ed1 100644 --- a/test/getImportMapFromProjectFiles/core/shared/root/package.json +++ b/test/getImportMapFromProjectFiles/core/shared/root/package.json @@ -1,7 +1,6 @@ { "name": "root", "type": "module", - "main": "", "dependencies": { "bar": "*", "foo": "*" diff --git a/test/getImportMapFromProjectFiles/core/shared/shared.test.js b/test/getImportMapFromProjectFiles/core/shared/shared.test.js index bd1e47cb..ffd46389 100644 --- a/test/getImportMapFromProjectFiles/core/shared/shared.test.js +++ b/test/getImportMapFromProjectFiles/core/shared/shared.test.js @@ -13,6 +13,7 @@ const importMap = await getImportMapFromProjectFiles({ const expected = { imports: { "bar/": "./node_modules/bar/", + "root": "./index.js", "bar": "./node_modules/bar/bar.js", "foo": "./node_modules/foo/foo.js", }, From b20297e936d1b7b41a98676805123aedf4e490a0 Mon Sep 17 00:00:00 2001 From: Damien Maillard Date: Fri, 12 Mar 2021 17:11:59 +0100 Subject: [PATCH 34/36] update tests --- .../from-js/getImportMapFromJsFiles.js | 4 +++ .../core/shared-indirect/root/index.js | 2 ++ .../root/node_modules/bar/bar.js | 4 +++ .../root/node_modules/foo/foo.js | 1 + .../core/shared-indirect/root/package.json | 1 - .../shared-indirect/shared-indirect.test.js | 27 ++++++++++--------- .../core/sibling-and-deep/root/index.js | 4 +++ .../root/node_modules/nested/index.js | 4 +++ .../nested/node_modules/bar/bar.js | 1 + .../nested/node_modules/foo/foo.js | 3 +++ .../sibling-and-deep/sibling-and-deep.test.js | 2 +- .../core/symlink/root/index.js | 2 ++ .../symlink/root/node_modules/foo/index.js | 2 ++ .../core/symlink/symlink.test.js | 1 - .../included-predicate.test.js | 3 ++- .../included-predicate/root/index.js | 2 ++ .../root/node_modules/bar}/index.js | 0 .../included-predicate/root/package.json | 1 - .../exports-pattern-directory.test.js | 2 +- .../exports-pattern-directory/root/index.js | 2 ++ .../root/node_modules/foo/index.js | 1 + .../exports-pattern-extensionless.test.js | 2 +- .../root/index.js | 2 ++ .../root/node_modules/foo/index.js} | 0 .../exports-sugar-conditional/root/index | 1 + .../root/node_modules/foo/index.browser.js | 0 .../root/node_modules/foo/index.default.js | 0 .../main-directory/main-directory.test.js | 2 +- .../main-directory/root/index.js | 2 ++ .../self-import/self-import-2/root/index.js | 2 ++ .../root/node_modules/foo/index.js | 1 + .../self-import/self-import-3/root/index.js | 6 +++++ .../self-import/self-import-3/root/lib/boo.js | 0 .../self-import-3/root/node_modules/foo/index | 0 .../{ => root}/node_modules/foo/package.json | 0 .../root/node_modules/foo/src/bar.js | 0 .../self-import-3/{ => root}/package.json | 0 .../self-import-3/self-import-3.test.js | 2 +- 38 files changed, 68 insertions(+), 21 deletions(-) create mode 100644 test/getImportMapFromProjectFiles/core/shared-indirect/root/index.js create mode 100644 test/getImportMapFromProjectFiles/core/sibling-and-deep/root/node_modules/nested/index.js create mode 100644 test/getImportMapFromProjectFiles/included-predicate/root/index.js rename test/getImportMapFromProjectFiles/{self-import/self-import-3 => included-predicate/root/node_modules/bar}/index.js (100%) create mode 100644 test/getImportMapFromProjectFiles/package-exports-field/exports-pattern-directory/root/node_modules/foo/index.js rename test/getImportMapFromProjectFiles/{package-main-field/main-directory/root/index => package-exports-field/exports-pattern-extensionless/root/node_modules/foo/index.js} (100%) create mode 100644 test/getImportMapFromProjectFiles/package-exports-field/exports-sugar-conditional/root/node_modules/foo/index.browser.js create mode 100644 test/getImportMapFromProjectFiles/package-exports-field/exports-sugar-conditional/root/node_modules/foo/index.default.js create mode 100644 test/getImportMapFromProjectFiles/package-main-field/main-directory/root/index.js create mode 100644 test/getImportMapFromProjectFiles/self-import/self-import-3/root/index.js create mode 100644 test/getImportMapFromProjectFiles/self-import/self-import-3/root/lib/boo.js create mode 100644 test/getImportMapFromProjectFiles/self-import/self-import-3/root/node_modules/foo/index rename test/getImportMapFromProjectFiles/self-import/self-import-3/{ => root}/node_modules/foo/package.json (100%) create mode 100644 test/getImportMapFromProjectFiles/self-import/self-import-3/root/node_modules/foo/src/bar.js rename test/getImportMapFromProjectFiles/self-import/self-import-3/{ => root}/package.json (100%) diff --git a/src/internal/from-js/getImportMapFromJsFiles.js b/src/internal/from-js/getImportMapFromJsFiles.js index 77c93cdb..bd577fab 100644 --- a/src/internal/from-js/getImportMapFromJsFiles.js +++ b/src/internal/from-js/getImportMapFromJsFiles.js @@ -62,6 +62,10 @@ export const getImportMapFromJsFiles = async ({ if (scope) { // make scope relative again scope = `./${urlToRelativeUrl(scope, projectDirectoryUrl)}` + // make from relative again + if (from.startsWith(projectDirectoryUrl)) { + from = `./${urlToRelativeUrl(from, projectDirectoryUrl)}` + } } markMappingAsUsed({ diff --git a/test/getImportMapFromProjectFiles/core/shared-indirect/root/index.js b/test/getImportMapFromProjectFiles/core/shared-indirect/root/index.js new file mode 100644 index 00000000..32d6c075 --- /dev/null +++ b/test/getImportMapFromProjectFiles/core/shared-indirect/root/index.js @@ -0,0 +1,2 @@ +/* eslint-disable import/no-unresolved */ +import "foo" diff --git a/test/getImportMapFromProjectFiles/core/shared-indirect/root/node_modules/bar/bar.js b/test/getImportMapFromProjectFiles/core/shared-indirect/root/node_modules/bar/bar.js index e69de29b..43048778 100644 --- a/test/getImportMapFromProjectFiles/core/shared-indirect/root/node_modules/bar/bar.js +++ b/test/getImportMapFromProjectFiles/core/shared-indirect/root/node_modules/bar/bar.js @@ -0,0 +1,4 @@ +import 'bar/bar.js' +import './bar.js' +// disabled because we test on file protocol +// import '/bar.js' \ No newline at end of file diff --git a/test/getImportMapFromProjectFiles/core/shared-indirect/root/node_modules/foo/foo.js b/test/getImportMapFromProjectFiles/core/shared-indirect/root/node_modules/foo/foo.js index e69de29b..e5bfaa3f 100644 --- a/test/getImportMapFromProjectFiles/core/shared-indirect/root/node_modules/foo/foo.js +++ b/test/getImportMapFromProjectFiles/core/shared-indirect/root/node_modules/foo/foo.js @@ -0,0 +1 @@ +import 'bar' \ No newline at end of file diff --git a/test/getImportMapFromProjectFiles/core/shared-indirect/root/package.json b/test/getImportMapFromProjectFiles/core/shared-indirect/root/package.json index b671dd4b..df39c719 100644 --- a/test/getImportMapFromProjectFiles/core/shared-indirect/root/package.json +++ b/test/getImportMapFromProjectFiles/core/shared-indirect/root/package.json @@ -1,7 +1,6 @@ { "name": "root", "type": "module", - "main": "", "dependencies": { "foo": "*" } diff --git a/test/getImportMapFromProjectFiles/core/shared-indirect/shared-indirect.test.js b/test/getImportMapFromProjectFiles/core/shared-indirect/shared-indirect.test.js index ed290558..276a8801 100644 --- a/test/getImportMapFromProjectFiles/core/shared-indirect/shared-indirect.test.js +++ b/test/getImportMapFromProjectFiles/core/shared-indirect/shared-indirect.test.js @@ -1,4 +1,4 @@ -import { normalizeImportMap, resolveImport } from "@jsenv/import-map" +// import { normalizeImportMap, resolveImport } from "@jsenv/import-map" import { resolveUrl } from "@jsenv/util" import { assert } from "@jsenv/assert" import { getImportMapFromProjectFiles } from "@jsenv/node-module-import-map" @@ -12,13 +12,15 @@ const importMap = await getImportMapFromProjectFiles({ const actual = importMap const expected = { imports: { + root: "./index.js", foo: "./node_modules/foo/foo.js", }, scopes: { "./node_modules/bar/": { "./node_modules/bar/": "./node_modules/bar/", "bar/": "./node_modules/bar/", - "./": "./node_modules/bar/", + // disabled because we are testing with file protocol + // "./": "./node_modules/bar/", }, "./node_modules/foo/": { bar: "./node_modules/bar/bar.js", @@ -28,13 +30,14 @@ const importMap = await getImportMapFromProjectFiles({ assert({ actual, expected }) } -{ - const importMapNormalized = normalizeImportMap(importMap, "http://example.com") - const actual = resolveImport({ - specifier: "http://example.com/file-inside-bar.js", - importer: `http://example.com/node_modules/bar/bar.js`, - importMap: importMapNormalized, - }) - const expected = `http://example.com/node_modules/bar/file-inside-bar.js` - assert({ actual, expected }) -} +// does not work with file:// protocol because / leads to filesystemroot +// { +// const importMapNormalized = normalizeImportMap(importMap, "http://example.com") +// const actual = resolveImport({ +// specifier: "http://example.com/file-inside-bar.js", +// importer: `http://example.com/node_modules/bar/bar.js`, +// importMap: importMapNormalized, +// }) +// const expected = `http://example.com/node_modules/bar/file-inside-bar.js` +// assert({ actual, expected }) +// } diff --git a/test/getImportMapFromProjectFiles/core/sibling-and-deep/root/index.js b/test/getImportMapFromProjectFiles/core/sibling-and-deep/root/index.js index e69de29b..cbc9b0d2 100644 --- a/test/getImportMapFromProjectFiles/core/sibling-and-deep/root/index.js +++ b/test/getImportMapFromProjectFiles/core/sibling-and-deep/root/index.js @@ -0,0 +1,4 @@ +/* eslint-disable import/no-unresolved */ +import "nested" +import "nested/index.js" +import "root/index.js" diff --git a/test/getImportMapFromProjectFiles/core/sibling-and-deep/root/node_modules/nested/index.js b/test/getImportMapFromProjectFiles/core/sibling-and-deep/root/node_modules/nested/index.js new file mode 100644 index 00000000..bfc7d07f --- /dev/null +++ b/test/getImportMapFromProjectFiles/core/sibling-and-deep/root/node_modules/nested/index.js @@ -0,0 +1,4 @@ +import 'foo' +import 'foo/foo.js' +import 'bar' +import 'bar/bar.js' \ No newline at end of file diff --git a/test/getImportMapFromProjectFiles/core/sibling-and-deep/root/node_modules/nested/node_modules/bar/bar.js b/test/getImportMapFromProjectFiles/core/sibling-and-deep/root/node_modules/nested/node_modules/bar/bar.js index e69de29b..d8ddb774 100644 --- a/test/getImportMapFromProjectFiles/core/sibling-and-deep/root/node_modules/nested/node_modules/bar/bar.js +++ b/test/getImportMapFromProjectFiles/core/sibling-and-deep/root/node_modules/nested/node_modules/bar/bar.js @@ -0,0 +1 @@ +import 'bar/bar.js' \ No newline at end of file diff --git a/test/getImportMapFromProjectFiles/core/sibling-and-deep/root/node_modules/nested/node_modules/foo/foo.js b/test/getImportMapFromProjectFiles/core/sibling-and-deep/root/node_modules/nested/node_modules/foo/foo.js index e69de29b..cbe4fb17 100644 --- a/test/getImportMapFromProjectFiles/core/sibling-and-deep/root/node_modules/nested/node_modules/foo/foo.js +++ b/test/getImportMapFromProjectFiles/core/sibling-and-deep/root/node_modules/nested/node_modules/foo/foo.js @@ -0,0 +1,3 @@ +import 'bar' +import 'bar/bar.js' +import 'foo/foo.js' \ No newline at end of file diff --git a/test/getImportMapFromProjectFiles/core/sibling-and-deep/sibling-and-deep.test.js b/test/getImportMapFromProjectFiles/core/sibling-and-deep/sibling-and-deep.test.js index d069e5fb..bca3d1cf 100644 --- a/test/getImportMapFromProjectFiles/core/sibling-and-deep/sibling-and-deep.test.js +++ b/test/getImportMapFromProjectFiles/core/sibling-and-deep/sibling-and-deep.test.js @@ -10,7 +10,7 @@ const actual = await getImportMapFromProjectFiles({ const expected = { imports: { "nested/": "./node_modules/nested/", - "nested": "./node_modules/nested/index", + "nested": "./node_modules/nested/index.js", "root/": "./", "root": "./index.js", }, diff --git a/test/getImportMapFromProjectFiles/core/symlink/root/index.js b/test/getImportMapFromProjectFiles/core/symlink/root/index.js index e69de29b..32d6c075 100644 --- a/test/getImportMapFromProjectFiles/core/symlink/root/index.js +++ b/test/getImportMapFromProjectFiles/core/symlink/root/index.js @@ -0,0 +1,2 @@ +/* eslint-disable import/no-unresolved */ +import "foo" diff --git a/test/getImportMapFromProjectFiles/core/symlink/root/node_modules/foo/index.js b/test/getImportMapFromProjectFiles/core/symlink/root/node_modules/foo/index.js index e69de29b..ca40a6b4 100644 --- a/test/getImportMapFromProjectFiles/core/symlink/root/node_modules/foo/index.js +++ b/test/getImportMapFromProjectFiles/core/symlink/root/node_modules/foo/index.js @@ -0,0 +1,2 @@ +import 'foo/index.js' +import './index.js' \ No newline at end of file diff --git a/test/getImportMapFromProjectFiles/core/symlink/symlink.test.js b/test/getImportMapFromProjectFiles/core/symlink/symlink.test.js index 72f00ac9..9c63aca4 100644 --- a/test/getImportMapFromProjectFiles/core/symlink/symlink.test.js +++ b/test/getImportMapFromProjectFiles/core/symlink/symlink.test.js @@ -16,7 +16,6 @@ const expected = { "./node_modules/foo/": { "./node_modules/foo/": "./node_modules/foo/", "foo/": "./node_modules/foo/", - "./": "./node_modules/foo/", }, }, } diff --git a/test/getImportMapFromProjectFiles/included-predicate/included-predicate.test.js b/test/getImportMapFromProjectFiles/included-predicate/included-predicate.test.js index bc6d941b..2bedc5e5 100644 --- a/test/getImportMapFromProjectFiles/included-predicate/included-predicate.test.js +++ b/test/getImportMapFromProjectFiles/included-predicate/included-predicate.test.js @@ -10,7 +10,8 @@ const actual = await getImportMapFromProjectFiles({ }) const expected = { imports: { - bar: "./node_modules/bar/index", + root: "./index.js", + bar: "./node_modules/bar/index.js", }, scopes: {}, } diff --git a/test/getImportMapFromProjectFiles/included-predicate/root/index.js b/test/getImportMapFromProjectFiles/included-predicate/root/index.js new file mode 100644 index 00000000..39f86a15 --- /dev/null +++ b/test/getImportMapFromProjectFiles/included-predicate/root/index.js @@ -0,0 +1,2 @@ +/* eslint-disable import/no-unresolved */ +import "bar" diff --git a/test/getImportMapFromProjectFiles/self-import/self-import-3/index.js b/test/getImportMapFromProjectFiles/included-predicate/root/node_modules/bar/index.js similarity index 100% rename from test/getImportMapFromProjectFiles/self-import/self-import-3/index.js rename to test/getImportMapFromProjectFiles/included-predicate/root/node_modules/bar/index.js diff --git a/test/getImportMapFromProjectFiles/included-predicate/root/package.json b/test/getImportMapFromProjectFiles/included-predicate/root/package.json index a73c1bd9..a6531a3c 100644 --- a/test/getImportMapFromProjectFiles/included-predicate/root/package.json +++ b/test/getImportMapFromProjectFiles/included-predicate/root/package.json @@ -1,7 +1,6 @@ { "name": "root", "type": "module", - "main": "", "dependencies": { "foo": "*", "bar": "*" diff --git a/test/getImportMapFromProjectFiles/package-exports-field/exports-pattern-directory/exports-pattern-directory.test.js b/test/getImportMapFromProjectFiles/package-exports-field/exports-pattern-directory/exports-pattern-directory.test.js index c7fcc2ab..470b7279 100644 --- a/test/getImportMapFromProjectFiles/package-exports-field/exports-pattern-directory/exports-pattern-directory.test.js +++ b/test/getImportMapFromProjectFiles/package-exports-field/exports-pattern-directory/exports-pattern-directory.test.js @@ -11,7 +11,7 @@ const expected = { imports: { "foo/": "./node_modules/foo/", "root": "./index.js", - "foo": "./node_modules/foo/index", + "foo": "./node_modules/foo/index.js", }, scopes: {}, } diff --git a/test/getImportMapFromProjectFiles/package-exports-field/exports-pattern-directory/root/index.js b/test/getImportMapFromProjectFiles/package-exports-field/exports-pattern-directory/root/index.js index e69de29b..32d6c075 100644 --- a/test/getImportMapFromProjectFiles/package-exports-field/exports-pattern-directory/root/index.js +++ b/test/getImportMapFromProjectFiles/package-exports-field/exports-pattern-directory/root/index.js @@ -0,0 +1,2 @@ +/* eslint-disable import/no-unresolved */ +import "foo" diff --git a/test/getImportMapFromProjectFiles/package-exports-field/exports-pattern-directory/root/node_modules/foo/index.js b/test/getImportMapFromProjectFiles/package-exports-field/exports-pattern-directory/root/node_modules/foo/index.js new file mode 100644 index 00000000..bdb45000 --- /dev/null +++ b/test/getImportMapFromProjectFiles/package-exports-field/exports-pattern-directory/root/node_modules/foo/index.js @@ -0,0 +1 @@ +import 'foo/index.js' \ No newline at end of file diff --git a/test/getImportMapFromProjectFiles/package-exports-field/exports-pattern-extensionless/exports-pattern-extensionless.test.js b/test/getImportMapFromProjectFiles/package-exports-field/exports-pattern-extensionless/exports-pattern-extensionless.test.js index 7c3b7eba..f4901bc8 100644 --- a/test/getImportMapFromProjectFiles/package-exports-field/exports-pattern-extensionless/exports-pattern-extensionless.test.js +++ b/test/getImportMapFromProjectFiles/package-exports-field/exports-pattern-extensionless/exports-pattern-extensionless.test.js @@ -33,7 +33,7 @@ https://github.com/WICG/import-maps/issues/232`, importMap: { imports: { root: "./index.js", - foo: "./node_modules/foo/index", + foo: "./node_modules/foo/index.js", }, scopes: {}, }, diff --git a/test/getImportMapFromProjectFiles/package-exports-field/exports-pattern-extensionless/root/index.js b/test/getImportMapFromProjectFiles/package-exports-field/exports-pattern-extensionless/root/index.js index e69de29b..05eed085 100644 --- a/test/getImportMapFromProjectFiles/package-exports-field/exports-pattern-extensionless/root/index.js +++ b/test/getImportMapFromProjectFiles/package-exports-field/exports-pattern-extensionless/root/index.js @@ -0,0 +1,2 @@ +// eslint-disable-next-line import/no-unresolved +import "foo" diff --git a/test/getImportMapFromProjectFiles/package-main-field/main-directory/root/index b/test/getImportMapFromProjectFiles/package-exports-field/exports-pattern-extensionless/root/node_modules/foo/index.js similarity index 100% rename from test/getImportMapFromProjectFiles/package-main-field/main-directory/root/index rename to test/getImportMapFromProjectFiles/package-exports-field/exports-pattern-extensionless/root/node_modules/foo/index.js diff --git a/test/getImportMapFromProjectFiles/package-exports-field/exports-sugar-conditional/root/index b/test/getImportMapFromProjectFiles/package-exports-field/exports-sugar-conditional/root/index index e69de29b..f90f31e8 100644 --- a/test/getImportMapFromProjectFiles/package-exports-field/exports-sugar-conditional/root/index +++ b/test/getImportMapFromProjectFiles/package-exports-field/exports-sugar-conditional/root/index @@ -0,0 +1 @@ +import 'foo' \ No newline at end of file diff --git a/test/getImportMapFromProjectFiles/package-exports-field/exports-sugar-conditional/root/node_modules/foo/index.browser.js b/test/getImportMapFromProjectFiles/package-exports-field/exports-sugar-conditional/root/node_modules/foo/index.browser.js new file mode 100644 index 00000000..e69de29b diff --git a/test/getImportMapFromProjectFiles/package-exports-field/exports-sugar-conditional/root/node_modules/foo/index.default.js b/test/getImportMapFromProjectFiles/package-exports-field/exports-sugar-conditional/root/node_modules/foo/index.default.js new file mode 100644 index 00000000..e69de29b diff --git a/test/getImportMapFromProjectFiles/package-main-field/main-directory/main-directory.test.js b/test/getImportMapFromProjectFiles/package-main-field/main-directory/main-directory.test.js index 90ebfaa8..3ea174a9 100644 --- a/test/getImportMapFromProjectFiles/package-main-field/main-directory/main-directory.test.js +++ b/test/getImportMapFromProjectFiles/package-main-field/main-directory/main-directory.test.js @@ -10,7 +10,7 @@ const actual = await getImportMapFromProjectFiles({ const expected = { imports: { "main-directory": "./node_modules/main-directory/lib/index.js", - "root": "./index", + "root": "./index.js", }, scopes: {}, } diff --git a/test/getImportMapFromProjectFiles/package-main-field/main-directory/root/index.js b/test/getImportMapFromProjectFiles/package-main-field/main-directory/root/index.js new file mode 100644 index 00000000..932d329f --- /dev/null +++ b/test/getImportMapFromProjectFiles/package-main-field/main-directory/root/index.js @@ -0,0 +1,2 @@ +/* eslint-disable import/no-unresolved */ +import "main-directory" diff --git a/test/getImportMapFromProjectFiles/self-import/self-import-2/root/index.js b/test/getImportMapFromProjectFiles/self-import/self-import-2/root/index.js index e69de29b..32d6c075 100644 --- a/test/getImportMapFromProjectFiles/self-import/self-import-2/root/index.js +++ b/test/getImportMapFromProjectFiles/self-import/self-import-2/root/index.js @@ -0,0 +1,2 @@ +/* eslint-disable import/no-unresolved */ +import "foo" diff --git a/test/getImportMapFromProjectFiles/self-import/self-import-2/root/node_modules/foo/index.js b/test/getImportMapFromProjectFiles/self-import/self-import-2/root/node_modules/foo/index.js index e69de29b..bdb45000 100644 --- a/test/getImportMapFromProjectFiles/self-import/self-import-2/root/node_modules/foo/index.js +++ b/test/getImportMapFromProjectFiles/self-import/self-import-2/root/node_modules/foo/index.js @@ -0,0 +1 @@ +import 'foo/index.js' \ No newline at end of file diff --git a/test/getImportMapFromProjectFiles/self-import/self-import-3/root/index.js b/test/getImportMapFromProjectFiles/self-import/self-import-3/root/index.js new file mode 100644 index 00000000..0bb64609 --- /dev/null +++ b/test/getImportMapFromProjectFiles/self-import/self-import-3/root/index.js @@ -0,0 +1,6 @@ +/* eslint-disable import/no-unresolved */ +import "foo" +import "foo/index" +import "foo/bar" +import "root/index.js" +import "root/boo" diff --git a/test/getImportMapFromProjectFiles/self-import/self-import-3/root/lib/boo.js b/test/getImportMapFromProjectFiles/self-import/self-import-3/root/lib/boo.js new file mode 100644 index 00000000..e69de29b diff --git a/test/getImportMapFromProjectFiles/self-import/self-import-3/root/node_modules/foo/index b/test/getImportMapFromProjectFiles/self-import/self-import-3/root/node_modules/foo/index new file mode 100644 index 00000000..e69de29b diff --git a/test/getImportMapFromProjectFiles/self-import/self-import-3/node_modules/foo/package.json b/test/getImportMapFromProjectFiles/self-import/self-import-3/root/node_modules/foo/package.json similarity index 100% rename from test/getImportMapFromProjectFiles/self-import/self-import-3/node_modules/foo/package.json rename to test/getImportMapFromProjectFiles/self-import/self-import-3/root/node_modules/foo/package.json diff --git a/test/getImportMapFromProjectFiles/self-import/self-import-3/root/node_modules/foo/src/bar.js b/test/getImportMapFromProjectFiles/self-import/self-import-3/root/node_modules/foo/src/bar.js new file mode 100644 index 00000000..e69de29b diff --git a/test/getImportMapFromProjectFiles/self-import/self-import-3/package.json b/test/getImportMapFromProjectFiles/self-import/self-import-3/root/package.json similarity index 100% rename from test/getImportMapFromProjectFiles/self-import/self-import-3/package.json rename to test/getImportMapFromProjectFiles/self-import/self-import-3/root/package.json diff --git a/test/getImportMapFromProjectFiles/self-import/self-import-3/self-import-3.test.js b/test/getImportMapFromProjectFiles/self-import/self-import-3/self-import-3.test.js index d87cd14e..7a861375 100644 --- a/test/getImportMapFromProjectFiles/self-import/self-import-3/self-import-3.test.js +++ b/test/getImportMapFromProjectFiles/self-import/self-import-3/self-import-3.test.js @@ -2,7 +2,7 @@ import { assert } from "@jsenv/assert" import { resolveUrl } from "@jsenv/util" import { getImportMapFromProjectFiles } from "@jsenv/node-module-import-map" -const testDirectoryUrl = resolveUrl("./", import.meta.url) +const testDirectoryUrl = resolveUrl("./root/", import.meta.url) const actual = await getImportMapFromProjectFiles({ projectDirectoryUrl: testDirectoryUrl, From c4a73f27fc537cf27f94a8ae8369c06f4dec4a0b Mon Sep 17 00:00:00 2001 From: Damien Maillard Date: Fri, 12 Mar 2021 17:16:06 +0100 Subject: [PATCH 35/36] update alpha version --- dist/commonjs/main.cjs | 83 +++++++++++++++++++++++++------------- dist/commonjs/main.cjs.map | 40 +++++++++--------- package.json | 2 +- 3 files changed, 77 insertions(+), 48 deletions(-) diff --git a/dist/commonjs/main.cjs b/dist/commonjs/main.cjs index 428c91cc..39d5fe37 100644 --- a/dist/commonjs/main.cjs +++ b/dist/commonjs/main.cjs @@ -9,18 +9,18 @@ var module$1 = require('module'); var cancellation = require('@jsenv/cancellation'); const memoizeAsyncFunctionByUrl = fn => { - const map = new WeakMap(); + const cache = {}; return memoizeAsyncFunction(fn, { getMemoryEntryFromArguments: ([url]) => { return { get: () => { - return map.get(url); + return cache[url]; }, set: promise => { - map.set(url, promise); + cache[url] = promise; }, delete: () => { - map.delete(url); + delete cache[url]; } }; } @@ -61,7 +61,7 @@ const memoizeAsyncFunctionBySpecifierAndImporter = fn => { const memoizeAsyncFunction = (fn, { getMemoryEntryFromArguments }) => { - return async (...args) => { + const memoized = async (...args) => { const memoryEntry = getMemoryEntryFromArguments(args); const promiseFromMemory = memoryEntry.get(); @@ -95,6 +95,12 @@ const memoizeAsyncFunction = (fn, { return promise; }; + + memoized.isInMemory = (...args) => { + return Boolean(getMemoryEntryFromArguments(args).get()); + }; + + return memoized; }; const createControllablePromise = () => { @@ -537,6 +543,15 @@ const getImportMapFromJsFiles = async ({ scope, from }) => { + if (scope) { + // make scope relative again + scope = `./${util.urlToRelativeUrl(scope, projectDirectoryUrl)}`; // make from relative again + + if (from.startsWith(projectDirectoryUrl)) { + from = `./${util.urlToRelativeUrl(from, projectDirectoryUrl)}`; + } + } + markMappingAsUsed({ scope, from, @@ -547,7 +562,7 @@ const getImportMapFromJsFiles = async ({ }); }; - const visitFile = async (specifier, importer, { + const resolveFileSystemUrl = memoizeAsyncFunctionBySpecifierAndImporter(async (specifier, importer, { importedBy }) => { let fileUrl; @@ -563,7 +578,7 @@ const getImportMapFromJsFiles = async ({ if (importer === projectPackageFileUrl) { // cannot find package main file (package.main is "" for instance) // we can't discover main file and parse dependencies - return; + return null; } gotBareSpecifierError = true; @@ -581,7 +596,7 @@ const getImportMapFromJsFiles = async ({ fileUrl, magicExtensions })); - return; + return null; } const needsAutoMapping = fileUrlOnFileSystem !== fileUrl || gotBareSpecifierError; @@ -607,17 +622,18 @@ const getImportMapFromJsFiles = async ({ })); } - await visitFileContent(fileUrlOnFileSystem); - }; - - const visitFileContent = memoizeAsyncFunctionByUrl(async fileUrl => { - const fileContent = await readFileContent(fileUrl); + return fileUrlOnFileSystem; + }); + const visitFile = memoizeAsyncFunctionByUrl(async fileUrl => { + const fileContent = await util.readFile(fileUrl, { + as: "string" + }); const specifiers = await parseSpecifiersFromFile(fileUrl, { fileContent }); - await Promise.all(Object.keys(specifiers).map(async specifier => { + const dependencies = await Promise.all(Object.keys(specifiers).map(async specifier => { const specifierInfo = specifiers[specifier]; - await visitFileMemoized(specifier, fileUrl, { + const dependencyUrlOnFileSystem = await resolveFileSystemUrl(specifier, fileUrl, { importedBy: showSource({ url: fileUrl, line: specifierInfo.line, @@ -625,21 +641,26 @@ const getImportMapFromJsFiles = async ({ source: fileContent }) }); + return dependencyUrlOnFileSystem; })); - }); - const visitFileMemoized = memoizeAsyncFunctionBySpecifierAndImporter(visitFile); - const readFileContent = memoizeAsyncFunctionByUrl(fileUrl => { - return util.readFile(fileUrl, { - as: "string" + const dependenciesToVisit = dependencies.filter(dependency => { + return dependency && !visitFile.isInMemory(dependency); }); + await Promise.all(dependenciesToVisit.map(dependency => { + return visitFile(dependency); + })); }); const projectPackageObject = await util.readFile(projectPackageFileUrl, { as: "json" }); - await visitFileMemoized(projectPackageObject.name, projectPackageFileUrl, { + const projectMainFileUrlOnFileSystem = await resolveFileSystemUrl(projectPackageObject.name, projectPackageFileUrl, { importedBy: projectPackageObject.exports ? `${projectPackageFileUrl}#exports` : `${projectPackageFileUrl}` }); + if (projectMainFileUrlOnFileSystem) { + await visitFile(projectMainFileUrlOnFileSystem); + } + if (removeUnusedMappings) { const importsUsed = {}; topLevelMappingsUsed.forEach(({ @@ -660,16 +681,16 @@ const getImportMapFromJsFiles = async ({ }); scopesUsed[scope] = scopedMappings; }); - return { + return importMap.sortImportMap({ imports: importsUsed, scopes: scopesUsed - }; + }); } - return { + return importMap.sortImportMap(importMap.composeTwoImportMaps(importMap$1, { imports, scopes - }; + })); }; const packageDirectoryUrlFromUrl = (url, projectDirectoryUrl) => { @@ -2064,8 +2085,12 @@ const getImportMapFromProjectFiles = async ({ ...rest }); importMapFromPackageFiles = importMap.sortImportMap(importMapFromPackageFiles); - let importMapFromJsFiles = jsFiles ? await getImportMapFromJsFiles({ - logLevel, + + if (!jsFiles) { + return importMapFromPackageFiles; + } + + let importMapFromJsFiles = await getImportMapFromJsFiles({ warn, importMap: importMapFromPackageFiles, removeUnusedMappings, @@ -2073,9 +2098,9 @@ const getImportMapFromProjectFiles = async ({ magicExtensions, packagesExportsPreference, runtime - }) : {}; + }); importMapFromJsFiles = importMap.sortImportMap(importMapFromJsFiles); - return importMap.sortImportMap(importMap.composeTwoImportMaps(importMapFromPackageFiles, importMapFromJsFiles)); + return importMapFromJsFiles; }; const runtimeExportsPreferences = { browser: ["browser"], diff --git a/dist/commonjs/main.cjs.map b/dist/commonjs/main.cjs.map index 8fb7f155..7b0d1937 100644 --- a/dist/commonjs/main.cjs.map +++ b/dist/commonjs/main.cjs.map @@ -23,12 +23,12 @@ "../../src/writeImportMapFile.js" ], "sourcesContent": [ - "export const memoizeAsyncFunctionByUrl = (fn) => {\n const map = new WeakMap()\n return memoizeAsyncFunction(fn, {\n getMemoryEntryFromArguments: ([url]) => {\n return {\n get: () => {\n return map.get(url)\n },\n set: (promise) => {\n map.set(url, promise)\n },\n delete: () => {\n map.delete(url)\n },\n }\n },\n })\n}\n\nexport const memoizeAsyncFunctionBySpecifierAndImporter = (fn) => {\n const importerCache = {}\n return memoizeAsyncFunction(fn, {\n getMemoryEntryFromArguments: ([specifier, importer]) => {\n return {\n get: () => {\n const specifierCacheForImporter = importerCache[importer]\n return specifierCacheForImporter ? specifierCacheForImporter[specifier] : null\n },\n set: (promise) => {\n const specifierCacheForImporter = importerCache[importer]\n if (specifierCacheForImporter) {\n specifierCacheForImporter[specifier] = promise\n } else {\n importerCache[importer] = {\n [specifier]: promise,\n }\n }\n },\n delete: () => {\n const specifierCacheForImporter = importerCache[importer]\n if (specifierCacheForImporter) {\n delete specifierCacheForImporter[specifier]\n }\n },\n }\n },\n })\n}\n\nconst memoizeAsyncFunction = (fn, { getMemoryEntryFromArguments }) => {\n return async (...args) => {\n const memoryEntry = getMemoryEntryFromArguments(args)\n const promiseFromMemory = memoryEntry.get()\n if (promiseFromMemory) {\n return promiseFromMemory\n }\n const { promise, resolve, reject } = createControllablePromise()\n memoryEntry.set(promise)\n let value\n let error\n try {\n value = fn(...args)\n error = false\n } catch (e) {\n value = e\n error = true\n memoryEntry.delete()\n }\n if (error) {\n reject(error)\n } else {\n resolve(value)\n }\n return promise\n }\n}\n\nconst createControllablePromise = () => {\n let resolve\n let reject\n const promise = new Promise((res, rej) => {\n resolve = res\n reject = rej\n })\n return { promise, resolve, reject }\n}\n", + "export const memoizeAsyncFunctionByUrl = (fn) => {\n const cache = {}\n return memoizeAsyncFunction(fn, {\n getMemoryEntryFromArguments: ([url]) => {\n return {\n get: () => {\n return cache[url]\n },\n set: (promise) => {\n cache[url] = promise\n },\n delete: () => {\n delete cache[url]\n },\n }\n },\n })\n}\n\nexport const memoizeAsyncFunctionBySpecifierAndImporter = (fn) => {\n const importerCache = {}\n return memoizeAsyncFunction(fn, {\n getMemoryEntryFromArguments: ([specifier, importer]) => {\n return {\n get: () => {\n const specifierCacheForImporter = importerCache[importer]\n return specifierCacheForImporter ? specifierCacheForImporter[specifier] : null\n },\n set: (promise) => {\n const specifierCacheForImporter = importerCache[importer]\n if (specifierCacheForImporter) {\n specifierCacheForImporter[specifier] = promise\n } else {\n importerCache[importer] = {\n [specifier]: promise,\n }\n }\n },\n delete: () => {\n const specifierCacheForImporter = importerCache[importer]\n if (specifierCacheForImporter) {\n delete specifierCacheForImporter[specifier]\n }\n },\n }\n },\n })\n}\n\nconst memoizeAsyncFunction = (fn, { getMemoryEntryFromArguments }) => {\n const memoized = async (...args) => {\n const memoryEntry = getMemoryEntryFromArguments(args)\n const promiseFromMemory = memoryEntry.get()\n if (promiseFromMemory) {\n return promiseFromMemory\n }\n const { promise, resolve, reject } = createControllablePromise()\n memoryEntry.set(promise)\n let value\n let error\n try {\n value = fn(...args)\n error = false\n } catch (e) {\n value = e\n error = true\n memoryEntry.delete()\n }\n if (error) {\n reject(error)\n } else {\n resolve(value)\n }\n return promise\n }\n memoized.isInMemory = (...args) => {\n return Boolean(getMemoryEntryFromArguments(args).get())\n }\n return memoized\n}\n\nconst createControllablePromise = () => {\n let resolve\n let reject\n const promise = new Promise((res, rej) => {\n resolve = res\n reject = rej\n })\n return { promise, resolve, reject }\n}\n", "/* global __filename */\n\nconst filenameContainsBackSlashes = __filename.indexOf(\"\\\\\") > -1\n\nconst url = filenameContainsBackSlashes\n ? `file:///${__filename.replace(/\\\\/g, \"/\")}`\n : `file://${__filename}`\n\nexport default url\n", "import { createRequire } from \"module\"\nimport { readFile, urlToFileSystemPath } from \"@jsenv/util\"\n\nconst require = createRequire(import.meta.url)\n\nconst parser = require(\"@babel/parser\")\nconst traverse = require(\"@babel/traverse\")\n\nexport const parseSpecifiersFromFile = async (\n fileUrl,\n {\n fileContent,\n sourceType = \"module\",\n allowImportExportEverywhere = true,\n allowAwaitOutsideFunction = true,\n ranges = true,\n jsx = true,\n typescript = fileUrl.endsWith(\".ts\") || fileUrl.endsWith(\".tsx\"),\n flow = false,\n ...options\n } = {},\n) => {\n fileContent = fileContent === undefined ? await readFile(fileUrl, { as: \"string\" }) : fileContent\n\n const ast = parser.parse(fileContent, {\n sourceType,\n sourceFilename: urlToFileSystemPath(fileUrl),\n allowImportExportEverywhere,\n allowAwaitOutsideFunction,\n ranges,\n plugins: [\n // \"estree\",\n \"topLevelAwait\",\n \"exportDefaultFrom\",\n ...(jsx ? [\"jsx\"] : []),\n ...(typescript ? [\"typescript\"] : []),\n ...(flow ? [\"flow\"] : []),\n ],\n ...options,\n })\n\n const specifiers = {}\n\n const addSpecifier = ({ path, type }) => {\n const specifier = path.node.value\n specifiers[specifier] = {\n line: path.node.loc.start.line,\n column: path.node.loc.start.column,\n type,\n }\n }\n\n traverse.default(ast, {\n // ImportExpression: (path) => {\n // if (path.node.arguments[0].type !== \"StringLiteral\") {\n // // Non-string argument, probably a variable or expression, e.g.\n // // import(moduleId)\n // // import('./' + moduleName)\n // return\n // }\n // addSpecifier(path.get(\"arguments\")[0])\n // },\n CallExpression: (path) => {\n if (path.node.callee.type !== \"Import\") {\n // Some other function call, not import();\n return\n }\n if (path.node.arguments[0].type !== \"StringLiteral\") {\n // Non-string argument, probably a variable or expression, e.g.\n // import(moduleId)\n // import('./' + moduleName)\n return\n }\n addSpecifier({\n path: path.get(\"arguments\")[0],\n type: \"import-dynamic\",\n })\n },\n ExportAllDeclaration: (path) => {\n addSpecifier({\n path: path.get(\"source\"),\n type: \"export-all\",\n })\n },\n ExportNamedDeclaration: (path) => {\n if (!path.node.source) {\n // This export has no \"source\", so it's probably\n // a local variable or function, e.g.\n // export { varName }\n // export const constName = ...\n // export function funcName() {}\n return\n }\n addSpecifier({\n path: path.get(\"source\"),\n type: \"export-named\",\n })\n },\n ImportDeclaration: (path) => {\n addSpecifier({\n path: path.get(\"source\"),\n type: \"import-static\",\n })\n },\n })\n\n return specifiers\n}\n", "// https://github.com/postcss/postcss/blob/fd30d3df5abc0954a0ec642a3cdc644ab2aacf9c/lib/css-syntax-error.js#L43\n// https://github.com/postcss/postcss/blob/fd30d3df5abc0954a0ec642a3cdc644ab2aacf9c/lib/terminal-highlight.js#L50\n// https://github.com/babel/babel/blob/eea156b2cb8deecfcf82d52aa1b71ba4995c7d68/packages/babel-code-frame/src/index.js#L1\n\nexport const showSource = ({ url, line, column, source }) => {\n let message = \"\"\n\n message += typeof url === \"undefined\" ? \"Anonymous\" : url\n if (typeof line !== \"number\") {\n return message\n }\n\n message += `:${line}`\n if (typeof column === \"number\") {\n message += `:${column}`\n }\n\n if (!source) {\n return message\n }\n\n return `${message}\n${showSourceLocation(source, {\n line,\n column,\n})}`\n}\n\nconst red = \"\\x1b[31m\"\nconst grey = \"\\x1b[39m\"\nconst ansiResetSequence = \"\\x1b[0m\"\n\nconst showSourceLocation = (\n source,\n {\n line,\n column,\n numberOfSurroundingLinesToShow = 1,\n lineMaxLength = 120,\n color = false,\n markColor = red,\n asideColor = grey,\n colorMark = (string) => `${markColor}${string}${ansiResetSequence}`,\n colorAside = (string) => `${asideColor}${string}${ansiResetSequence}`,\n },\n) => {\n const mark = color ? colorMark : (string) => string\n const aside = color ? colorAside : (string) => string\n\n const lines = source.split(/\\r?\\n/)\n let lineRange = {\n start: line - 1,\n end: line,\n }\n lineRange = moveLineRangeUp(lineRange, numberOfSurroundingLinesToShow)\n lineRange = moveLineRangeDown(lineRange, numberOfSurroundingLinesToShow)\n lineRange = lineRangeWithinLines(lineRange, lines)\n const linesToShow = lines.slice(lineRange.start, lineRange.end)\n const endLineNumber = lineRange.end\n const lineNumberMaxWidth = String(endLineNumber).length\n\n const columnRange = {}\n if (column === undefined) {\n columnRange.start = 0\n columnRange.end = lineMaxLength\n } else if (column > lineMaxLength) {\n columnRange.start = column - Math.floor(lineMaxLength / 2)\n columnRange.end = column + Math.ceil(lineMaxLength / 2)\n } else {\n columnRange.start = 0\n columnRange.end = lineMaxLength\n }\n\n return linesToShow.map((lineSource, index) => {\n const lineNumber = lineRange.start + index + 1\n const isMainLine = lineNumber === line\n const lineSourceTruncated = applyColumnRange(columnRange, lineSource)\n const lineNumberWidth = String(lineNumber).length\n // ensure if line moves from 7,8,9 to 10 the display is still great\n const lineNumberRightSpacing = \" \".repeat(lineNumberMaxWidth - lineNumberWidth)\n const asideSource = `${lineNumber}${lineNumberRightSpacing} |`\n const lineFormatted = `${aside(asideSource)} ${lineSourceTruncated}`\n if (isMainLine) {\n if (column === undefined) {\n return `${mark(\">\")} ${lineFormatted}`\n }\n const lineSourceUntilColumn = lineSourceTruncated.slice(0, column - columnRange.start)\n const spacing = stringToSpaces(lineSourceUntilColumn)\n const mainLineFormatted = `${mark(\">\")} ${lineFormatted}\n ${\" \".repeat(lineNumberWidth)} ${aside(\"|\")}${spacing}${mark(\"^\")}`\n return mainLineFormatted\n }\n return ` ${lineFormatted}`\n }).join(`\n`)\n}\n\nconst applyColumnRange = ({ start, end }, line) => {\n if (typeof start !== \"number\") {\n throw new TypeError(`start must be a number, received ${start}`)\n }\n if (typeof end !== \"number\") {\n throw new TypeError(`end must be a number, received ${end}`)\n }\n if (end < start) {\n throw new Error(`end must be greater than start, but ${end} is smaller than ${start}`)\n }\n\n const prefix = \"…\"\n const suffix = \"…\"\n const lastIndex = line.length\n\n if (line.length === 0) {\n // don't show any ellipsis if the line is empty\n // because it's not truncated in that case\n return \"\"\n }\n\n const startTruncated = start > 0\n const endTruncated = lastIndex > end\n\n let from = startTruncated ? start + prefix.length : start\n let to = endTruncated ? end - suffix.length : end\n if (to > lastIndex) to = lastIndex\n\n if (start >= lastIndex || from === to) {\n return \"\"\n }\n\n let result = \"\"\n while (from < to) {\n result += line[from]\n from++\n }\n\n if (result.length === 0) {\n return \"\"\n }\n if (startTruncated && endTruncated) {\n return `${prefix}${result}${suffix}`\n }\n if (startTruncated) {\n return `${prefix}${result}`\n }\n if (endTruncated) {\n return `${result}${suffix}`\n }\n return result\n}\n\nconst stringToSpaces = (string) => string.replace(/[^\\t]/g, \" \")\n\n// const getLineRangeLength = ({ start, end }) => end - start\n\nconst moveLineRangeUp = ({ start, end }, number) => {\n return {\n start: start - number,\n end,\n }\n}\n\nconst moveLineRangeDown = ({ start, end }, number) => {\n return {\n start,\n end: end + number,\n }\n}\n\nconst lineRangeWithinLines = ({ start, end }, lines) => {\n return {\n start: start < 0 ? 0 : start,\n end: end > lines.length ? lines.length : end,\n }\n}\n", "import { resolveUrl, readFileSystemNodeStat, urlToFilename, urlToExtension } from \"@jsenv/util\"\nimport { firstOperationMatching } from \"@jsenv/cancellation\"\n\nexport const resolveFile = async (fileUrl, { magicExtensions }) => {\n const fileStat = await readFileSystemNodeStat(fileUrl, {\n nullIfNotFound: true,\n })\n\n // file found\n if (fileStat && fileStat.isFile()) {\n return fileUrl\n }\n\n // directory found\n if (fileStat && fileStat.isDirectory()) {\n const indexFileSuffix = fileUrl.endsWith(\"/\") ? \"index\" : \"/index\"\n const indexFileUrl = `${fileUrl}${indexFileSuffix}`\n const extensionLeadingToAFile = await findExtensionLeadingToFile(indexFileUrl, magicExtensions)\n if (extensionLeadingToAFile === null) {\n return null\n }\n return `${indexFileUrl}${extensionLeadingToAFile}`\n }\n\n // file not found and it has an extension\n const extension = urlToExtension(fileUrl)\n if (extension !== \"\") {\n return null\n }\n\n const extensionLeadingToAFile = await findExtensionLeadingToFile(fileUrl, magicExtensions)\n // magic extension not found\n if (extensionLeadingToAFile === null) {\n return null\n }\n\n // magic extension worked\n return `${fileUrl}${extensionLeadingToAFile}`\n}\n\nconst findExtensionLeadingToFile = async (fileUrl, magicExtensions) => {\n const urlDirectoryUrl = resolveUrl(\"./\", fileUrl)\n const urlFilename = urlToFilename(fileUrl)\n const extensionLeadingToFile = await firstOperationMatching({\n array: magicExtensions,\n start: async (extensionCandidate) => {\n const urlCandidate = `${urlDirectoryUrl}${urlFilename}${extensionCandidate}`\n const stats = await readFileSystemNodeStat(urlCandidate, { nullIfNotFound: true })\n return stats && stats.isFile() ? extensionCandidate : null\n },\n predicate: (extension) => Boolean(extension),\n })\n return extensionLeadingToFile || null\n}\n", - "import { createDetailedMessage } from \"@jsenv/logger\"\nimport { resolveUrl, readFile, urlToExtension, urlToRelativeUrl } from \"@jsenv/util\"\nimport { normalizeImportMap, resolveImport } from \"@jsenv/import-map\"\nimport {\n memoizeAsyncFunctionByUrl,\n memoizeAsyncFunctionBySpecifierAndImporter,\n} from \"../memoizeAsyncFunction.js\"\nimport { parseSpecifiersFromFile } from \"./parseSpecifiersFromFile.js\"\nimport { showSource } from \"./showSource.js\"\nimport { resolveFile } from \"../resolveFile.js\"\n\nconst BARE_SPECIFIER_ERROR = {}\n\nexport const getImportMapFromJsFiles = async ({\n warn,\n importMap,\n projectDirectoryUrl,\n removeUnusedMappings,\n magicExtensions = [\".js\", \".jsx\", \".ts\", \".tsx\", \".node\", \".json\"],\n}) => {\n const projectPackageFileUrl = resolveUrl(\"./package.json\", projectDirectoryUrl)\n\n const imports = {}\n const scopes = {}\n const addMapping = ({ scope, from, to }) => {\n if (scope) {\n scopes[scope] = {\n ...(scopes[scope] || {}),\n [from]: to,\n }\n } else {\n imports[from] = to\n }\n }\n\n const topLevelMappingsUsed = []\n const scopedMappingsUsed = {}\n const markMappingAsUsed = ({ scope, from, to }) => {\n if (scope) {\n if (scope in scopedMappingsUsed) {\n scopedMappingsUsed[scope].push({ from, to })\n } else {\n scopedMappingsUsed[scope] = [{ from, to }]\n }\n } else {\n topLevelMappingsUsed.push({ from, to })\n }\n }\n const importMapNormalized = normalizeImportMap(importMap, projectDirectoryUrl)\n const trackAndResolveImport = (specifier, importer) => {\n return resolveImport({\n specifier,\n importer,\n importMap: importMapNormalized,\n defaultExtension: false,\n onImportMapping: ({ scope, from }) => {\n markMappingAsUsed({\n scope,\n from,\n to: scope ? importMap.scopes[scope][from] : importMap.imports[from],\n })\n },\n createBareSpecifierError: () => BARE_SPECIFIER_ERROR,\n })\n }\n\n const visitFile = async (specifier, importer, { importedBy }) => {\n let fileUrl\n let gotBareSpecifierError = false\n\n try {\n fileUrl = trackAndResolveImport(specifier, importer)\n } catch (e) {\n if (e !== BARE_SPECIFIER_ERROR) {\n throw e\n }\n if (importer === projectPackageFileUrl) {\n // cannot find package main file (package.main is \"\" for instance)\n // we can't discover main file and parse dependencies\n return\n }\n gotBareSpecifierError = true\n fileUrl = resolveUrl(specifier, importer)\n }\n\n const fileUrlOnFileSystem = await resolveFile(fileUrl, {\n magicExtensions: magicExtensionWithImporterExtension(magicExtensions, importer),\n })\n\n if (!fileUrlOnFileSystem) {\n warn(\n createFileNotFoundWarning({\n specifier,\n importedBy,\n fileUrl,\n magicExtensions,\n }),\n )\n return\n }\n\n const needsAutoMapping = fileUrlOnFileSystem !== fileUrl || gotBareSpecifierError\n if (needsAutoMapping) {\n const packageDirectoryUrl = packageDirectoryUrlFromUrl(fileUrl, projectDirectoryUrl)\n const packageFileUrl = resolveUrl(\"package.json\", packageDirectoryUrl)\n const autoMapping = {\n scope:\n packageFileUrl === projectPackageFileUrl\n ? undefined\n : `./${urlToRelativeUrl(packageDirectoryUrl, projectDirectoryUrl)}`,\n from: specifier,\n to: `./${urlToRelativeUrl(fileUrlOnFileSystem, projectDirectoryUrl)}`,\n }\n addMapping(autoMapping)\n markMappingAsUsed(autoMapping)\n warn(\n formatAutoMappingSpecifierWarning({\n specifier,\n importedBy,\n autoMapping,\n closestPackageDirectoryUrl: packageDirectoryUrl,\n closestPackageObject: await readFile(packageFileUrl, { as: \"json\" }),\n }),\n )\n }\n\n await visitFileContent(fileUrlOnFileSystem)\n }\n\n const visitFileContent = memoizeAsyncFunctionByUrl(async (fileUrl) => {\n const fileContent = await readFileContent(fileUrl)\n const specifiers = await parseSpecifiersFromFile(fileUrl, { fileContent })\n\n await Promise.all(\n Object.keys(specifiers).map(async (specifier) => {\n const specifierInfo = specifiers[specifier]\n await visitFileMemoized(specifier, fileUrl, {\n importedBy: showSource({\n url: fileUrl,\n line: specifierInfo.line,\n column: specifierInfo.column,\n source: fileContent,\n }),\n })\n }),\n )\n })\n const visitFileMemoized = memoizeAsyncFunctionBySpecifierAndImporter(visitFile)\n\n const readFileContent = memoizeAsyncFunctionByUrl((fileUrl) => {\n return readFile(fileUrl, { as: \"string\" })\n })\n\n const projectPackageObject = await readFile(projectPackageFileUrl, { as: \"json\" })\n await visitFileMemoized(projectPackageObject.name, projectPackageFileUrl, {\n importedBy: projectPackageObject.exports\n ? `${projectPackageFileUrl}#exports`\n : `${projectPackageFileUrl}`,\n })\n\n if (removeUnusedMappings) {\n const importsUsed = {}\n topLevelMappingsUsed.forEach(({ from, to }) => {\n importsUsed[from] = to\n })\n const scopesUsed = {}\n Object.keys(scopedMappingsUsed).forEach((scope) => {\n const mappingsUsed = scopedMappingsUsed[scope]\n const scopedMappings = {}\n mappingsUsed.forEach(({ from, to }) => {\n scopedMappings[from] = to\n })\n scopesUsed[scope] = scopedMappings\n })\n return {\n imports: importsUsed,\n scopes: scopesUsed,\n }\n }\n\n return { imports, scopes }\n}\n\nconst packageDirectoryUrlFromUrl = (url, projectDirectoryUrl) => {\n const relativeUrl = urlToRelativeUrl(url, projectDirectoryUrl)\n\n const lastNodeModulesDirectoryStartIndex = relativeUrl.lastIndexOf(\"node_modules/\")\n if (lastNodeModulesDirectoryStartIndex === -1) {\n return projectDirectoryUrl\n }\n\n const lastNodeModulesDirectoryEndIndex =\n lastNodeModulesDirectoryStartIndex + `node_modules/`.length\n\n const beforeNodeModulesLastDirectory = relativeUrl.slice(0, lastNodeModulesDirectoryEndIndex)\n const afterLastNodeModulesDirectory = relativeUrl.slice(lastNodeModulesDirectoryEndIndex)\n const remainingDirectories = afterLastNodeModulesDirectory.split(\"/\")\n\n if (afterLastNodeModulesDirectory[0] === \"@\") {\n // scoped package\n return `${projectDirectoryUrl}${beforeNodeModulesLastDirectory}${remainingDirectories\n .slice(0, 2)\n .join(\"/\")}`\n }\n return `${projectDirectoryUrl}${beforeNodeModulesLastDirectory}${remainingDirectories[0]}/`\n}\n\nconst magicExtensionWithImporterExtension = (magicExtensions, importer) => {\n const importerExtension = urlToExtension(importer)\n const magicExtensionsWithoutImporterExtension = magicExtensions.filter(\n (ext) => ext !== importerExtension,\n )\n return [importerExtension, ...magicExtensionsWithoutImporterExtension]\n}\n\nconst createFileNotFoundWarning = ({ specifier, importedBy, fileUrl, magicExtensions }) => {\n return {\n code: \"FILE_NOT_FOUND\",\n message: createDetailedMessage(`Cannot find file for \"${specifier}\"`, {\n \"specifier origin\": importedBy,\n \"file url tried\": fileUrl,\n ...(urlToExtension(fileUrl) === \"\"\n ? { [\"extensions tried\"]: magicExtensions.join(`, `) }\n : {}),\n }),\n }\n}\n\nconst formatAutoMappingSpecifierWarning = ({\n importedBy,\n autoMapping,\n closestPackageDirectoryUrl,\n closestPackageObject,\n}) => {\n return {\n code: \"AUTO_MAPPING\",\n message: createDetailedMessage(`Auto mapping ${autoMapping.from} to ${autoMapping.to}.`, {\n \"specifier origin\": importedBy,\n \"suggestion\": decideAutoMappingSuggestion({\n autoMapping,\n closestPackageDirectoryUrl,\n closestPackageObject,\n }),\n }),\n }\n}\n\nconst decideAutoMappingSuggestion = ({\n autoMapping,\n closestPackageDirectoryUrl,\n closestPackageObject,\n}) => {\n if (typeof closestPackageObject.importmap === \"string\") {\n const packageImportmapFileUrl = resolveUrl(\n closestPackageObject.importmap,\n closestPackageDirectoryUrl,\n )\n\n return `To get rid of this warning, add an explicit mapping into importmap file.\n${mappingToImportmapString(autoMapping)}\ninto ${packageImportmapFileUrl}.`\n }\n\n return `To get rid of this warning, add an explicit mapping into package.json.\n${mappingToExportsFieldString(autoMapping)}\ninto ${closestPackageDirectoryUrl}package.json.`\n}\n\nconst mappingToImportmapString = ({ scope, from, to }) => {\n if (scope) {\n return JSON.stringify(\n {\n scopes: {\n [scope]: {\n [from]: to,\n },\n },\n },\n null,\n \" \",\n )\n }\n\n return JSON.stringify(\n {\n imports: {\n [from]: to,\n },\n },\n null,\n \" \",\n )\n}\n\nconst mappingToExportsFieldString = ({ scope, from, to }) => {\n if (scope) {\n const scopeUrl = resolveUrl(scope, \"file://\")\n const toUrl = resolveUrl(to, \"file://\")\n to = `./${urlToRelativeUrl(toUrl, scopeUrl)}`\n }\n\n return JSON.stringify(\n {\n exports: {\n [from]: to,\n },\n },\n null,\n \" \",\n )\n}\n", + "import { createDetailedMessage } from \"@jsenv/logger\"\nimport { resolveUrl, readFile, urlToExtension, urlToRelativeUrl } from \"@jsenv/util\"\nimport {\n normalizeImportMap,\n resolveImport,\n sortImportMap,\n composeTwoImportMaps,\n} from \"@jsenv/import-map\"\nimport {\n memoizeAsyncFunctionByUrl,\n memoizeAsyncFunctionBySpecifierAndImporter,\n} from \"../memoizeAsyncFunction.js\"\nimport { parseSpecifiersFromFile } from \"./parseSpecifiersFromFile.js\"\nimport { showSource } from \"./showSource.js\"\nimport { resolveFile } from \"../resolveFile.js\"\n\nconst BARE_SPECIFIER_ERROR = {}\n\nexport const getImportMapFromJsFiles = async ({\n warn,\n importMap,\n projectDirectoryUrl,\n removeUnusedMappings,\n magicExtensions = [\".js\", \".jsx\", \".ts\", \".tsx\", \".node\", \".json\"],\n}) => {\n const projectPackageFileUrl = resolveUrl(\"./package.json\", projectDirectoryUrl)\n\n const imports = {}\n const scopes = {}\n const addMapping = ({ scope, from, to }) => {\n if (scope) {\n scopes[scope] = {\n ...(scopes[scope] || {}),\n [from]: to,\n }\n } else {\n imports[from] = to\n }\n }\n\n const topLevelMappingsUsed = []\n const scopedMappingsUsed = {}\n const markMappingAsUsed = ({ scope, from, to }) => {\n if (scope) {\n if (scope in scopedMappingsUsed) {\n scopedMappingsUsed[scope].push({ from, to })\n } else {\n scopedMappingsUsed[scope] = [{ from, to }]\n }\n } else {\n topLevelMappingsUsed.push({ from, to })\n }\n }\n const importMapNormalized = normalizeImportMap(importMap, projectDirectoryUrl)\n const trackAndResolveImport = (specifier, importer) => {\n return resolveImport({\n specifier,\n importer,\n importMap: importMapNormalized,\n defaultExtension: false,\n onImportMapping: ({ scope, from }) => {\n if (scope) {\n // make scope relative again\n scope = `./${urlToRelativeUrl(scope, projectDirectoryUrl)}`\n // make from relative again\n if (from.startsWith(projectDirectoryUrl)) {\n from = `./${urlToRelativeUrl(from, projectDirectoryUrl)}`\n }\n }\n\n markMappingAsUsed({\n scope,\n from,\n to: scope ? importMap.scopes[scope][from] : importMap.imports[from],\n })\n },\n createBareSpecifierError: () => BARE_SPECIFIER_ERROR,\n })\n }\n\n const resolveFileSystemUrl = memoizeAsyncFunctionBySpecifierAndImporter(\n async (specifier, importer, { importedBy }) => {\n let fileUrl\n let gotBareSpecifierError = false\n\n try {\n fileUrl = trackAndResolveImport(specifier, importer)\n } catch (e) {\n if (e !== BARE_SPECIFIER_ERROR) {\n throw e\n }\n if (importer === projectPackageFileUrl) {\n // cannot find package main file (package.main is \"\" for instance)\n // we can't discover main file and parse dependencies\n return null\n }\n gotBareSpecifierError = true\n fileUrl = resolveUrl(specifier, importer)\n }\n\n const fileUrlOnFileSystem = await resolveFile(fileUrl, {\n magicExtensions: magicExtensionWithImporterExtension(magicExtensions, importer),\n })\n\n if (!fileUrlOnFileSystem) {\n warn(\n createFileNotFoundWarning({\n specifier,\n importedBy,\n fileUrl,\n magicExtensions,\n }),\n )\n return null\n }\n\n const needsAutoMapping = fileUrlOnFileSystem !== fileUrl || gotBareSpecifierError\n if (needsAutoMapping) {\n const packageDirectoryUrl = packageDirectoryUrlFromUrl(fileUrl, projectDirectoryUrl)\n const packageFileUrl = resolveUrl(\"package.json\", packageDirectoryUrl)\n const autoMapping = {\n scope:\n packageFileUrl === projectPackageFileUrl\n ? undefined\n : `./${urlToRelativeUrl(packageDirectoryUrl, projectDirectoryUrl)}`,\n from: specifier,\n to: `./${urlToRelativeUrl(fileUrlOnFileSystem, projectDirectoryUrl)}`,\n }\n addMapping(autoMapping)\n markMappingAsUsed(autoMapping)\n warn(\n formatAutoMappingSpecifierWarning({\n specifier,\n importedBy,\n autoMapping,\n closestPackageDirectoryUrl: packageDirectoryUrl,\n closestPackageObject: await readFile(packageFileUrl, { as: \"json\" }),\n }),\n )\n }\n\n return fileUrlOnFileSystem\n },\n )\n\n const visitFile = memoizeAsyncFunctionByUrl(async (fileUrl) => {\n const fileContent = await readFile(fileUrl, { as: \"string\" })\n const specifiers = await parseSpecifiersFromFile(fileUrl, { fileContent })\n\n const dependencies = await Promise.all(\n Object.keys(specifiers).map(async (specifier) => {\n const specifierInfo = specifiers[specifier]\n const dependencyUrlOnFileSystem = await resolveFileSystemUrl(specifier, fileUrl, {\n importedBy: showSource({\n url: fileUrl,\n line: specifierInfo.line,\n column: specifierInfo.column,\n source: fileContent,\n }),\n })\n return dependencyUrlOnFileSystem\n }),\n )\n const dependenciesToVisit = dependencies.filter((dependency) => {\n return dependency && !visitFile.isInMemory(dependency)\n })\n await Promise.all(\n dependenciesToVisit.map((dependency) => {\n return visitFile(dependency)\n }),\n )\n })\n\n const projectPackageObject = await readFile(projectPackageFileUrl, { as: \"json\" })\n const projectMainFileUrlOnFileSystem = await resolveFileSystemUrl(\n projectPackageObject.name,\n projectPackageFileUrl,\n {\n importedBy: projectPackageObject.exports\n ? `${projectPackageFileUrl}#exports`\n : `${projectPackageFileUrl}`,\n },\n )\n if (projectMainFileUrlOnFileSystem) {\n await visitFile(projectMainFileUrlOnFileSystem)\n }\n\n if (removeUnusedMappings) {\n const importsUsed = {}\n topLevelMappingsUsed.forEach(({ from, to }) => {\n importsUsed[from] = to\n })\n const scopesUsed = {}\n Object.keys(scopedMappingsUsed).forEach((scope) => {\n const mappingsUsed = scopedMappingsUsed[scope]\n const scopedMappings = {}\n mappingsUsed.forEach(({ from, to }) => {\n scopedMappings[from] = to\n })\n scopesUsed[scope] = scopedMappings\n })\n return sortImportMap({\n imports: importsUsed,\n scopes: scopesUsed,\n })\n }\n\n return sortImportMap(composeTwoImportMaps(importMap, { imports, scopes }))\n}\n\nconst packageDirectoryUrlFromUrl = (url, projectDirectoryUrl) => {\n const relativeUrl = urlToRelativeUrl(url, projectDirectoryUrl)\n\n const lastNodeModulesDirectoryStartIndex = relativeUrl.lastIndexOf(\"node_modules/\")\n if (lastNodeModulesDirectoryStartIndex === -1) {\n return projectDirectoryUrl\n }\n\n const lastNodeModulesDirectoryEndIndex =\n lastNodeModulesDirectoryStartIndex + `node_modules/`.length\n\n const beforeNodeModulesLastDirectory = relativeUrl.slice(0, lastNodeModulesDirectoryEndIndex)\n const afterLastNodeModulesDirectory = relativeUrl.slice(lastNodeModulesDirectoryEndIndex)\n const remainingDirectories = afterLastNodeModulesDirectory.split(\"/\")\n\n if (afterLastNodeModulesDirectory[0] === \"@\") {\n // scoped package\n return `${projectDirectoryUrl}${beforeNodeModulesLastDirectory}${remainingDirectories\n .slice(0, 2)\n .join(\"/\")}`\n }\n return `${projectDirectoryUrl}${beforeNodeModulesLastDirectory}${remainingDirectories[0]}/`\n}\n\nconst magicExtensionWithImporterExtension = (magicExtensions, importer) => {\n const importerExtension = urlToExtension(importer)\n const magicExtensionsWithoutImporterExtension = magicExtensions.filter(\n (ext) => ext !== importerExtension,\n )\n return [importerExtension, ...magicExtensionsWithoutImporterExtension]\n}\n\nconst createFileNotFoundWarning = ({ specifier, importedBy, fileUrl, magicExtensions }) => {\n return {\n code: \"FILE_NOT_FOUND\",\n message: createDetailedMessage(`Cannot find file for \"${specifier}\"`, {\n \"specifier origin\": importedBy,\n \"file url tried\": fileUrl,\n ...(urlToExtension(fileUrl) === \"\"\n ? { [\"extensions tried\"]: magicExtensions.join(`, `) }\n : {}),\n }),\n }\n}\n\nconst formatAutoMappingSpecifierWarning = ({\n importedBy,\n autoMapping,\n closestPackageDirectoryUrl,\n closestPackageObject,\n}) => {\n return {\n code: \"AUTO_MAPPING\",\n message: createDetailedMessage(`Auto mapping ${autoMapping.from} to ${autoMapping.to}.`, {\n \"specifier origin\": importedBy,\n \"suggestion\": decideAutoMappingSuggestion({\n autoMapping,\n closestPackageDirectoryUrl,\n closestPackageObject,\n }),\n }),\n }\n}\n\nconst decideAutoMappingSuggestion = ({\n autoMapping,\n closestPackageDirectoryUrl,\n closestPackageObject,\n}) => {\n if (typeof closestPackageObject.importmap === \"string\") {\n const packageImportmapFileUrl = resolveUrl(\n closestPackageObject.importmap,\n closestPackageDirectoryUrl,\n )\n\n return `To get rid of this warning, add an explicit mapping into importmap file.\n${mappingToImportmapString(autoMapping)}\ninto ${packageImportmapFileUrl}.`\n }\n\n return `To get rid of this warning, add an explicit mapping into package.json.\n${mappingToExportsFieldString(autoMapping)}\ninto ${closestPackageDirectoryUrl}package.json.`\n}\n\nconst mappingToImportmapString = ({ scope, from, to }) => {\n if (scope) {\n return JSON.stringify(\n {\n scopes: {\n [scope]: {\n [from]: to,\n },\n },\n },\n null,\n \" \",\n )\n }\n\n return JSON.stringify(\n {\n imports: {\n [from]: to,\n },\n },\n null,\n \" \",\n )\n}\n\nconst mappingToExportsFieldString = ({ scope, from, to }) => {\n if (scope) {\n const scopeUrl = resolveUrl(scope, \"file://\")\n const toUrl = resolveUrl(to, \"file://\")\n to = `./${urlToRelativeUrl(toUrl, scopeUrl)}`\n }\n\n return JSON.stringify(\n {\n exports: {\n [from]: to,\n },\n },\n null,\n \" \",\n )\n}\n", "export const optimizeImportMap = ({ imports, scopes }) => {\n // remove useless duplicates (scoped key+value already defined on imports)\n const scopesOptimized = {}\n Object.keys(scopes).forEach((scope) => {\n const scopeMappings = scopes[scope]\n const scopeMappingsOptimized = {}\n Object.keys(scopeMappings).forEach((mappingKey) => {\n const topLevelMappingValue = imports[mappingKey]\n const mappingValue = scopeMappings[mappingKey]\n if (!topLevelMappingValue || topLevelMappingValue !== mappingValue) {\n scopeMappingsOptimized[mappingKey] = mappingValue\n }\n })\n if (Object.keys(scopeMappingsOptimized).length > 0) {\n scopesOptimized[scope] = scopeMappingsOptimized\n }\n })\n return { imports, scopes: scopesOptimized }\n}\n", "import { createDetailedMessage } from \"@jsenv/logger\"\nimport { resolveUrl, urlToFileSystemPath, urlToExtension } from \"@jsenv/util\"\nimport { resolveFile } from \"../resolveFile.js\"\n\nconst magicExtensions = [\".js\", \".json\", \".node\"]\n\nexport const resolvePackageMain = ({\n warn,\n packagesExportsPreference,\n packageFileUrl,\n packageJsonObject,\n}) => {\n if (packagesExportsPreference.includes(\"import\") && \"module\" in packageJsonObject) {\n return resolveMainFile({\n warn,\n packageFileUrl,\n packageMainFieldName: \"module\",\n packageMainFieldValue: packageJsonObject.module,\n })\n }\n\n if (packagesExportsPreference.includes(\"import\") && \"jsnext:main\" in packageJsonObject) {\n return resolveMainFile({\n warn,\n packageFileUrl,\n packageMainFieldName: \"jsnext:main\",\n packageMainFieldValue: packageJsonObject[\"jsnext:main\"],\n })\n }\n\n if (\n packagesExportsPreference.includes(\"browser\") &&\n \"browser\" in packageJsonObject &&\n // when it's an object it means some files\n // should be replaced with an other, let's ignore this when we are searching\n // for the main file\n typeof packageJsonObject.browser === \"string\"\n ) {\n return resolveMainFile({\n warn,\n packageFileUrl,\n packageMainFieldName: \"browser\",\n packageMainFieldValue: packageJsonObject.browser,\n })\n }\n\n if (\"main\" in packageJsonObject) {\n return resolveMainFile({\n warn,\n packageFileUrl,\n packageMainFieldName: \"main\",\n packageMainFieldValue: packageJsonObject.main,\n })\n }\n\n return resolveMainFile({\n warn,\n packageFileUrl,\n packageMainFieldName: \"default\",\n packageMainFieldValue: \"index\",\n })\n}\n\nconst resolveMainFile = async ({\n warn,\n packageFileUrl,\n packageMainFieldName,\n packageMainFieldValue,\n}) => {\n // main is explicitely empty meaning\n // it is assumed that we should not find a file\n if (packageMainFieldValue === \"\") {\n return null\n }\n\n const packageDirectoryUrl = resolveUrl(\"./\", packageFileUrl)\n const mainFileRelativeUrl = packageMainFieldValue.endsWith(\"/\")\n ? `${packageMainFieldValue}index`\n : packageMainFieldValue\n\n const mainFileUrlFirstCandidate = resolveUrl(mainFileRelativeUrl, packageFileUrl)\n\n if (!mainFileUrlFirstCandidate.startsWith(packageDirectoryUrl)) {\n warn(\n createPackageMainFileMustBeRelativeWarning({\n packageMainFieldName,\n packageMainFieldValue,\n packageFileUrl,\n }),\n )\n return null\n }\n\n const mainFileUrl = await resolveFile(mainFileUrlFirstCandidate, {\n magicExtensions,\n })\n\n if (!mainFileUrl) {\n // we know in advance this remapping does not lead to an actual file.\n // we only warn because we have no guarantee this remapping will actually be used\n // in the codebase.\n // warn only if there is actually a main field\n // otherwise the package.json is missing the main field\n // it certainly means it's not important\n if (packageMainFieldName !== \"default\") {\n warn(\n createPackageMainFileNotFoundWarning({\n specifier: packageMainFieldValue,\n importedIn: `${packageFileUrl}#${packageMainFieldName}`,\n fileUrl: mainFileUrlFirstCandidate,\n magicExtensions,\n }),\n )\n }\n return mainFileUrlFirstCandidate\n }\n\n return mainFileUrl\n}\n\nconst createPackageMainFileMustBeRelativeWarning = ({\n packageMainFieldName,\n packageMainFieldValue,\n packageFileUrl,\n}) => {\n return {\n code: \"PACKAGE_MAIN_FILE_MUST_BE_RELATIVE\",\n message: `${packageMainFieldName} field in package.json must be inside package.json folder.\n--- ${packageMainFieldName} ---\n${packageMainFieldValue}\n--- package.json path ---\n${urlToFileSystemPath(packageFileUrl)}`,\n }\n}\n\nconst createPackageMainFileNotFoundWarning = ({\n specifier,\n importedIn,\n fileUrl,\n magicExtensions,\n}) => {\n return {\n code: \"PACKAGE_MAIN_FILE_NOT_FOUND\",\n message: createDetailedMessage(`Cannot find package main file \"${specifier}\"`, {\n \"imported in\": importedIn,\n \"file url tried\": fileUrl,\n ...(urlToExtension(fileUrl) === \"\"\n ? { [\"extensions tried\"]: magicExtensions.join(`, `) }\n : {}),\n }),\n }\n}\n", "import { resolveUrl, moveImportMap } from \"@jsenv/import-map\"\nimport { readFile, urlToFileSystemPath } from \"@jsenv/util\"\n\nexport const visitPackageImportMap = async ({\n warn,\n packageFileUrl,\n packageJsonObject,\n packageImportmap = packageJsonObject.importmap,\n projectDirectoryUrl,\n}) => {\n if (typeof packageImportmap === \"undefined\") {\n return {}\n }\n\n if (typeof packageImportmap === \"string\") {\n const importmapFileUrl = resolveUrl(packageImportmap, packageFileUrl)\n const importmap = await readFile(importmapFileUrl, { as: \"json\" })\n return moveImportMap(importmap, importmapFileUrl, projectDirectoryUrl)\n }\n\n if (typeof packageImportmap === \"object\" && packageImportmap !== null) {\n return packageImportmap\n }\n\n warn(\n createPackageImportMapUnexpectedWarning({\n packageImportmap,\n packageFileUrl,\n }),\n )\n return {}\n}\n\nconst createPackageImportMapUnexpectedWarning = ({ packageImportmap, packageFileUrl }) => {\n return {\n code: \"PACKAGE_IMPORTMAP_UNEXPECTED\",\n message: `unexpected value in package.json importmap field: value must be a string or an object.\n--- value ---\n${packageImportmap}\n--- package.json path ---\n${urlToFileSystemPath(packageFileUrl)}`,\n }\n}\n", @@ -37,8 +37,8 @@ "export const applyPackageManualOverride = (packageObject, packagesManualOverrides) => {\n const { name, version } = packageObject\n const overrideKey = Object.keys(packagesManualOverrides).find((overrideKeyCandidate) => {\n if (name === overrideKeyCandidate) {\n return true\n }\n if (`${name}@${version}` === overrideKeyCandidate) {\n return true\n }\n return false\n })\n if (overrideKey) {\n return composeObject(packageObject, packagesManualOverrides[overrideKey])\n }\n return packageObject\n}\n\nconst composeObject = (leftObject, rightObject) => {\n const composedObject = {\n ...leftObject,\n }\n Object.keys(rightObject).forEach((key) => {\n const rightValue = rightObject[key]\n\n if (rightValue === null || typeof rightValue !== \"object\" || key in leftObject === false) {\n composedObject[key] = rightValue\n } else {\n const leftValue = leftObject[key]\n if (leftValue === null || typeof leftValue !== \"object\") {\n composedObject[key] = rightValue\n } else {\n composedObject[key] = composeObject(leftValue, rightValue)\n }\n }\n })\n return composedObject\n}\n", "import { readFile, urlToFileSystemPath } from \"@jsenv/util\"\nimport { applyPackageManualOverride } from \"./applyPackageManualOverride.js\"\n\nexport const PACKAGE_NOT_FOUND = {}\nexport const PACKAGE_WITH_SYNTAX_ERROR = {}\n\nexport const readPackageFile = async (packageFileUrl, packagesManualOverrides) => {\n try {\n const packageObject = await readFile(packageFileUrl, { as: \"json\" })\n return applyPackageManualOverride(packageObject, packagesManualOverrides)\n } catch (e) {\n if (e.code === \"ENOENT\") {\n return PACKAGE_NOT_FOUND\n }\n\n if (e.name === \"SyntaxError\") {\n console.error(formatPackageSyntaxErrorLog({ syntaxError: e, packageFileUrl }))\n return PACKAGE_WITH_SYNTAX_ERROR\n }\n\n throw e\n }\n}\n\nconst formatPackageSyntaxErrorLog = ({ syntaxError, packageFileUrl }) => {\n return `\nerror while parsing package.json.\n--- syntax error message ---\n${syntaxError.message}\n--- package.json path ---\n${urlToFileSystemPath(packageFileUrl)}\n`\n}\n", "import { firstOperationMatching } from \"@jsenv/cancellation\"\nimport { urlToRelativeUrl, resolveUrl } from \"@jsenv/util\"\nimport { memoizeAsyncFunctionByUrl } from \"../memoizeAsyncFunction.js\"\nimport { readPackageFile, PACKAGE_NOT_FOUND, PACKAGE_WITH_SYNTAX_ERROR } from \"./readPackageFile.js\"\n\nexport const createFindNodeModulePackage = (packagesManualOverrides) => {\n const readPackageFileMemoized = memoizeAsyncFunctionByUrl((packageFileUrl) => {\n return readPackageFile(packageFileUrl, packagesManualOverrides)\n })\n\n return ({ projectDirectoryUrl, packageFileUrl, dependencyName }) => {\n const nodeModuleCandidates = getNodeModuleCandidates(packageFileUrl, projectDirectoryUrl)\n\n return firstOperationMatching({\n array: nodeModuleCandidates,\n start: async (nodeModuleCandidate) => {\n const packageFileUrlCandidate = `${projectDirectoryUrl}${nodeModuleCandidate}${dependencyName}/package.json`\n const packageObjectCandidate = await readPackageFileMemoized(packageFileUrlCandidate)\n return {\n packageFileUrl: packageFileUrlCandidate,\n packageJsonObject: packageObjectCandidate,\n syntaxError: packageObjectCandidate === PACKAGE_WITH_SYNTAX_ERROR,\n }\n },\n predicate: ({ packageJsonObject }) => {\n return packageJsonObject !== PACKAGE_NOT_FOUND\n },\n })\n }\n}\n\nconst getNodeModuleCandidates = (fileUrl, projectDirectoryUrl) => {\n const fileDirectoryUrl = resolveUrl(\"./\", fileUrl)\n\n if (fileDirectoryUrl === projectDirectoryUrl) {\n return [`node_modules/`]\n }\n\n const fileDirectoryRelativeUrl = urlToRelativeUrl(fileDirectoryUrl, projectDirectoryUrl)\n const candidates = []\n const relativeNodeModuleDirectoryArray = fileDirectoryRelativeUrl.split(\"node_modules/\")\n // remove the first empty string\n relativeNodeModuleDirectoryArray.shift()\n\n let i = relativeNodeModuleDirectoryArray.length\n while (i--) {\n candidates.push(\n `node_modules/${relativeNodeModuleDirectoryArray\n .slice(0, i + 1)\n .join(\"node_modules/\")}node_modules/`,\n )\n }\n\n return [...candidates, \"node_modules/\"]\n}\n", - "import { createDetailedMessage } from \"@jsenv/logger\"\nimport {\n resolveUrl,\n urlToRelativeUrl,\n assertAndNormalizeDirectoryUrl,\n urlToFileSystemPath,\n urlToBasename,\n readFile,\n} from \"@jsenv/util\"\nimport { optimizeImportMap } from \"../optimizeImportMap.js\"\nimport { resolvePackageMain } from \"./resolvePackageMain.js\"\nimport { visitPackageImportMap } from \"./visitPackageImportMap.js\"\nimport { visitPackageExports } from \"./visitPackageExports.js\"\nimport { createFindNodeModulePackage } from \"./node-module-resolution.js\"\n\nexport const getImportMapFromPackageFiles = async ({\n // nothing is actually listening for this cancellationToken for now\n // it's not very important but it would be better to register on it\n // an stops what we are doing if asked to do so\n // cancellationToken = createCancellationTokenForProcess(),\n logger,\n warn,\n projectDirectoryUrl,\n projectPackageDevDependenciesIncluded = process.env.NODE_ENV !== \"production\",\n packagesExportsPreference = [\"import\", \"browser\"],\n packagesExportsIncluded = true,\n packagesManualOverrides = {},\n packageIncludedPredicate = () => true,\n}) => {\n projectDirectoryUrl = assertAndNormalizeDirectoryUrl(projectDirectoryUrl)\n\n const projectPackageFileUrl = resolveUrl(\"./package.json\", projectDirectoryUrl)\n const findNodeModulePackage = createFindNodeModulePackage(packagesManualOverrides)\n\n const imports = {}\n const scopes = {}\n const addMapping = ({ scope, from, to }) => {\n if (scope) {\n // when a package says './' maps to './'\n // we must add something to say if we are already inside the package\n // no need to ensure leading slash are scoped to the package\n if (from === \"./\" && to === scope) {\n addMapping({\n scope,\n from: scope,\n to: scope,\n })\n const packageName = scope.slice(scope.lastIndexOf(\"node_modules/\") + `node_modules/`.length)\n addMapping({\n scope,\n from: packageName,\n to: scope,\n })\n }\n\n scopes[scope] = {\n ...(scopes[scope] || {}),\n [from]: to,\n }\n } else {\n // we could think it's useless to remap from with to\n // however it can be used to ensure a weaker remapping\n // does not win over this specific file or folder\n if (from === to) {\n /**\n * however remapping '/' to '/' is truly useless\n * moreover it would make wrapImportMap create something like\n * {\n * imports: {\n * \"/\": \"/.dist/best/\"\n * }\n * }\n * that would append the wrapped folder twice\n * */\n if (from === \"/\") return\n }\n imports[from] = to\n }\n }\n\n const seen = {}\n const markPackageAsSeen = (packageFileUrl, importerPackageFileUrl) => {\n if (packageFileUrl in seen) {\n seen[packageFileUrl].push(importerPackageFileUrl)\n } else {\n seen[packageFileUrl] = [importerPackageFileUrl]\n }\n }\n const packageIsSeen = (packageFileUrl, importerPackageFileUrl) => {\n return packageFileUrl in seen && seen[packageFileUrl].includes(importerPackageFileUrl)\n }\n\n const visit = async ({\n packageFileUrl,\n packageName,\n packageJsonObject,\n importerPackageFileUrl,\n importerPackageJsonObject,\n includeDevDependencies,\n }) => {\n if (!packageIncludedPredicate({ packageName, packageFileUrl, packageJsonObject })) {\n return\n }\n\n await visitDependencies({\n packageFileUrl,\n packageJsonObject,\n includeDevDependencies,\n })\n await visitPackage({\n packageFileUrl,\n packageName,\n packageJsonObject,\n importerPackageFileUrl,\n importerPackageJsonObject,\n })\n }\n\n const visitPackage = async ({\n packageFileUrl,\n packageName,\n packageJsonObject,\n importerPackageFileUrl,\n }) => {\n const packageInfo = computePackageInfo({\n packageFileUrl,\n packageName,\n importerPackageFileUrl,\n })\n\n await visitPackageMain({\n packageFileUrl,\n packageName,\n packageJsonObject,\n packageInfo,\n })\n\n const {\n importerIsRoot,\n importerRelativeUrl,\n packageIsRoot,\n packageDirectoryRelativeUrl,\n // packageDirectoryUrl,\n // packageDirectoryUrlExpected,\n } = packageInfo\n\n const addImportMapForPackage = (importMap) => {\n if (packageIsRoot) {\n const { imports = {}, scopes = {} } = importMap\n Object.keys(imports).forEach((from) => {\n addMapping({\n from,\n to: imports[from],\n })\n })\n Object.keys(scopes).forEach((scope) => {\n const scopeMappings = scopes[scope]\n Object.keys(scopeMappings).forEach((key) => {\n addMapping({\n scope,\n from: key,\n to: scopeMappings[key],\n })\n })\n })\n return\n }\n\n const { imports = {}, scopes = {} } = importMap\n const scope = `./${packageDirectoryRelativeUrl}`\n Object.keys(imports).forEach((from) => {\n const to = imports[from]\n const toMoved = moveMappingValue(to, packageFileUrl, projectDirectoryUrl)\n addMapping({\n scope,\n from,\n to: toMoved,\n })\n })\n Object.keys(scopes).forEach((scope) => {\n const scopeMappings = scopes[scope]\n const scopeMoved = moveMappingValue(scope, packageFileUrl, projectDirectoryUrl)\n Object.keys(scopeMappings).forEach((key) => {\n const to = scopeMappings[key]\n const toMoved = moveMappingValue(to, packageFileUrl, projectDirectoryUrl)\n addMapping({\n scope: scopeMoved,\n from: key,\n to: toMoved,\n })\n })\n })\n }\n\n const addMappingsForPackageAndImporter = (mappings) => {\n if (packageIsRoot) {\n Object.keys(mappings).forEach((from) => {\n const to = mappings[from]\n addMapping({\n from,\n to,\n })\n })\n return\n }\n\n if (importerIsRoot) {\n // own package mappings available to himself\n Object.keys(mappings).forEach((from) => {\n const to = mappings[from]\n addMapping({\n scope: `./${packageDirectoryRelativeUrl}`,\n from,\n to,\n })\n addMapping({ from, to })\n })\n\n // if importer is root no need to make package mappings available to the importer\n // because they are already on top level mappings\n return\n }\n\n Object.keys(mappings).forEach((from) => {\n const to = mappings[from]\n // own package exports available to himself\n addMapping({\n scope: `./${packageDirectoryRelativeUrl}`,\n from,\n to,\n })\n // now make package exports available to the importer\n // here if the importer is himself we could do stuff\n // we should even handle the case earlier to prevent top level remapping\n addMapping({\n scope: `./${importerRelativeUrl}`,\n from,\n to,\n })\n })\n }\n\n const importsFromPackageField = await visitPackageImportMap({\n warn,\n packageFileUrl,\n packageJsonObject,\n projectDirectoryUrl,\n })\n addImportMapForPackage(importsFromPackageField)\n\n if (packagesExportsIncluded && \"exports\" in packageJsonObject) {\n const mappingsFromPackageExports = {}\n visitPackageExports({\n warn,\n packageFileUrl,\n packageJsonObject,\n packageName,\n projectDirectoryUrl,\n packagesExportsPreference,\n onExport: ({ key, value }) => {\n const from = key\n const to = value\n\n if (from.indexOf(\"*\") === -1) {\n mappingsFromPackageExports[from] = to\n return\n }\n\n if (\n from.endsWith(\"/*\") &&\n to.endsWith(\"/*\") &&\n // ensure ends with '*' AND there is only one '*' occurence\n to.indexOf(\"*\") === to.length - 1\n ) {\n const fromWithouTrailingStar = from.slice(0, -1)\n const toWithoutTrailingStar = to.slice(0, -1)\n mappingsFromPackageExports[fromWithouTrailingStar] = toWithoutTrailingStar\n return\n }\n\n warn(\n createExportsWildcardIgnoredWarning({\n key,\n value,\n packageFileUrl,\n }),\n )\n },\n })\n addMappingsForPackageAndImporter(mappingsFromPackageExports)\n }\n }\n\n const visitPackageMain = async ({\n packageFileUrl,\n packageName,\n packageJsonObject,\n packageInfo: {\n importerIsRoot,\n importerRelativeUrl,\n packageDirectoryUrl,\n packageDirectoryUrlExpected,\n },\n }) => {\n const mainFileUrl = await resolvePackageMain({\n warn,\n packagesExportsPreference,\n packageFileUrl,\n packageJsonObject,\n })\n\n // it's possible to have no main\n // like { main: \"\" } in package.json\n // or a main that does not lead to an actual file\n if (mainFileUrl === null) {\n return\n }\n\n const mainFileRelativeUrl = urlToRelativeUrl(mainFileUrl, projectDirectoryUrl)\n const from = packageName\n const to = `./${mainFileRelativeUrl}`\n\n if (importerIsRoot) {\n addMapping({ from, to })\n } else {\n addMapping({\n scope: `./${importerRelativeUrl}`,\n from,\n to,\n })\n }\n if (packageDirectoryUrl !== packageDirectoryUrlExpected) {\n addMapping({\n scope: `./${importerRelativeUrl}`,\n from,\n to,\n })\n }\n }\n\n const visitDependencies = async ({\n packageFileUrl,\n packageJsonObject,\n includeDevDependencies,\n }) => {\n const dependencyMap = packageDependenciesFromPackageObject(packageJsonObject, {\n includeDevDependencies,\n })\n\n await Promise.all(\n Object.keys(dependencyMap).map(async (dependencyName) => {\n const dependencyInfo = dependencyMap[dependencyName]\n await visitDependency({\n packageFileUrl,\n packageJsonObject,\n dependencyName,\n dependencyInfo,\n })\n }),\n )\n }\n\n const visitDependency = async ({\n packageFileUrl,\n packageJsonObject,\n dependencyName,\n dependencyInfo,\n }) => {\n const dependencyData = await findDependency({\n packageFileUrl,\n dependencyName,\n })\n if (!dependencyData) {\n const cannotFindPackageWarning = createCannotFindPackageWarning({\n dependencyName,\n dependencyInfo,\n packageFileUrl,\n })\n if (dependencyInfo.isOptional) {\n logger.debug(cannotFindPackageWarning.message)\n } else {\n warn(cannotFindPackageWarning)\n }\n\n return\n }\n if (dependencyData.syntaxError) {\n return\n }\n\n const {\n packageFileUrl: dependencyPackageFileUrl,\n packageJsonObject: dependencyPackageJsonObject,\n } = dependencyData\n\n if (packageIsSeen(dependencyPackageFileUrl, packageFileUrl)) {\n return\n }\n markPackageAsSeen(dependencyPackageFileUrl, packageFileUrl)\n await visit({\n packageFileUrl: dependencyPackageFileUrl,\n packageName: dependencyName,\n packageJsonObject: dependencyPackageJsonObject,\n importerPackageFileUrl: packageFileUrl,\n importerPackageJsonObject: packageJsonObject,\n })\n }\n\n const computePackageInfo = ({ packageFileUrl, packageName, importerPackageFileUrl }) => {\n const importerIsRoot = importerPackageFileUrl === projectPackageFileUrl\n\n const importerPackageDirectoryUrl = resolveUrl(\"./\", importerPackageFileUrl)\n\n const importerRelativeUrl = urlToRelativeUrl(importerPackageDirectoryUrl, projectDirectoryUrl)\n\n const packageIsRoot = packageFileUrl === projectPackageFileUrl\n\n const packageDirectoryUrl = resolveUrl(\"./\", packageFileUrl)\n\n const packageDirectoryUrlExpected = `${importerPackageDirectoryUrl}node_modules/${packageName}/`\n\n const packageDirectoryRelativeUrl = urlToRelativeUrl(packageDirectoryUrl, projectDirectoryUrl)\n\n return {\n importerIsRoot,\n importerRelativeUrl,\n packageIsRoot,\n packageDirectoryUrl,\n packageDirectoryUrlExpected,\n packageDirectoryRelativeUrl,\n }\n }\n\n const dependenciesCache = {}\n const findDependency = ({ packageFileUrl, dependencyName }) => {\n if (packageFileUrl in dependenciesCache === false) {\n dependenciesCache[packageFileUrl] = {}\n }\n if (dependencyName in dependenciesCache[packageFileUrl]) {\n return dependenciesCache[packageFileUrl][dependencyName]\n }\n const dependencyPromise = findNodeModulePackage({\n projectDirectoryUrl,\n packageFileUrl,\n dependencyName,\n })\n dependenciesCache[packageFileUrl][dependencyName] = dependencyPromise\n return dependencyPromise\n }\n\n const projectPackageJsonObject = await readFile(projectPackageFileUrl, { as: \"json\" })\n const importerPackageFileUrl = projectPackageFileUrl\n markPackageAsSeen(projectPackageFileUrl, importerPackageFileUrl)\n\n const packageName = projectPackageJsonObject.name\n if (typeof packageName !== \"string\") {\n warn(\n createPackageNameMustBeAStringWarning({\n packageName,\n packageFileUrl: projectPackageFileUrl,\n }),\n )\n return {}\n }\n\n await visit({\n packageFileUrl: projectPackageFileUrl,\n packageName: projectPackageJsonObject.name,\n packageJsonObject: projectPackageJsonObject,\n importerPackageFileUrl,\n importerPackageJsonObject: null,\n includeDevDependencies: projectPackageDevDependenciesIncluded,\n })\n\n return optimizeImportMap({ imports, scopes })\n}\n\nconst packageDependenciesFromPackageObject = (packageObject, { includeDevDependencies }) => {\n const packageDependencies = {}\n\n const { dependencies = {} } = packageObject\n // https://npm.github.io/using-pkgs-docs/package-json/types/optionaldependencies.html\n const { optionalDependencies = {} } = packageObject\n Object.keys(dependencies).forEach((dependencyName) => {\n packageDependencies[dependencyName] = {\n type: \"dependency\",\n isOptional: dependencyName in optionalDependencies,\n versionPattern: dependencies[dependencyName],\n }\n })\n\n const { peerDependencies = {} } = packageObject\n const { peerDependenciesMeta = {} } = packageObject\n Object.keys(peerDependencies).forEach((dependencyName) => {\n packageDependencies[dependencyName] = {\n type: \"peerDependency\",\n versionPattern: peerDependencies[dependencyName],\n isOptional:\n dependencyName in peerDependenciesMeta && peerDependenciesMeta[dependencyName].optional,\n }\n })\n\n if (includeDevDependencies) {\n const { devDependencies = {} } = packageObject\n Object.keys(devDependencies).forEach((dependencyName) => {\n if (!packageDependencies.hasOwnProperty(dependencyName)) {\n packageDependencies[dependencyName] = {\n type: \"devDependency\",\n versionPattern: devDependencies[dependencyName],\n }\n }\n })\n }\n\n return packageDependencies\n}\n\nconst moveMappingValue = (address, from, to) => {\n const url = resolveUrl(address, from)\n const relativeUrl = urlToRelativeUrl(url, to)\n if (relativeUrl.startsWith(\"../\")) {\n return relativeUrl\n }\n if (relativeUrl.startsWith(\"./\")) {\n return relativeUrl\n }\n if (/^[a-zA-Z]{2,}:/.test(relativeUrl)) {\n // has sheme\n return relativeUrl\n }\n return `./${relativeUrl}`\n}\n\nconst createExportsWildcardIgnoredWarning = ({ key, value, packageFileUrl }) => {\n return {\n code: \"EXPORTS_WILDCARD\",\n message: `Ignoring export using \"*\" because it is not supported by importmap.\n--- key ---\n${key}\n--- value ---\n${value}\n--- package.json path ---\n${urlToFileSystemPath(packageFileUrl)}\n--- see also ---\nhttps://github.com/WICG/import-maps/issues/232`,\n }\n}\n\nconst createPackageNameMustBeAStringWarning = ({ packageName, packageFileUrl }) => {\n return {\n code: \"PACKAGE_NAME_MUST_BE_A_STRING\",\n message: `package name field must be a string\n--- package name field ---\n${packageName}\n--- package.json file path ---\n${packageFileUrl}`,\n }\n}\n\nconst createCannotFindPackageWarning = ({ dependencyName, dependencyInfo, packageFileUrl }) => {\n const dependencyIsOptional = dependencyInfo.isOptional\n const dependencyType = dependencyInfo.type\n const dependencyVersionPattern = dependencyInfo.versionPattern\n return {\n code: \"CANNOT_FIND_PACKAGE\",\n message: createDetailedMessage(\n dependencyIsOptional\n ? `cannot find an optional ${dependencyType}.`\n : `cannot find a ${dependencyType}.`,\n {\n [dependencyType]: `${dependencyName}@${dependencyVersionPattern}`,\n \"required by\": urlToFileSystemPath(packageFileUrl),\n },\n ),\n }\n}\n", - "import { sortImportMap, composeTwoImportMaps } from \"@jsenv/import-map\"\nimport { createLogger } from \"@jsenv/logger\"\nimport { getImportMapFromJsFiles } from \"./internal/from-js/getImportMapFromJsFiles.js\"\nimport { getImportMapFromPackageFiles } from \"./internal/from-package/getImportMapFromPackageFiles.js\"\n\nexport const getImportMapFromProjectFiles = async ({\n logLevel,\n projectDirectoryUrl,\n runtime = \"browser\",\n moduleFormat = \"esm\",\n dev = false,\n jsFiles = true,\n removeUnusedMappings = !dev,\n magicExtensions,\n onWarn = (warning, warn) => {\n warn(warning)\n },\n ...rest\n}) => {\n const packagesExportsPreference = [\n ...(moduleFormatPreferences[moduleFormat] || [moduleFormat]),\n ...(runtimeExportsPreferences[runtime] || [runtime]),\n ...(dev ? \"development\" : \"production\"),\n ]\n\n const logger = createLogger({ logLevel })\n const warn = (warning) => {\n onWarn(warning, () => {\n logger.warn(`\\n${warning.message}\\n`)\n })\n }\n\n // At this point, importmap is relative to the project directory url\n let importMapFromPackageFiles = await getImportMapFromPackageFiles({\n logger,\n warn,\n projectDirectoryUrl,\n packagesExportsPreference,\n projectPackageDevDependenciesIncluded: dev,\n ...rest,\n })\n importMapFromPackageFiles = sortImportMap(importMapFromPackageFiles)\n\n let importMapFromJsFiles = jsFiles\n ? await getImportMapFromJsFiles({\n logLevel,\n warn,\n importMap: importMapFromPackageFiles,\n removeUnusedMappings,\n projectDirectoryUrl,\n magicExtensions,\n packagesExportsPreference,\n runtime,\n })\n : {}\n importMapFromJsFiles = sortImportMap(importMapFromJsFiles)\n\n return sortImportMap(composeTwoImportMaps(importMapFromPackageFiles, importMapFromJsFiles))\n}\n\nconst runtimeExportsPreferences = {\n browser: [\"browser\"],\n node: [\"node\"],\n}\n\nconst moduleFormatPreferences = {\n esm: [\"import\"],\n cjs: [\"require\"],\n}\n", + "import { createDetailedMessage } from \"@jsenv/logger\"\nimport {\n resolveUrl,\n urlToRelativeUrl,\n assertAndNormalizeDirectoryUrl,\n urlToFileSystemPath,\n readFile,\n} from \"@jsenv/util\"\nimport { optimizeImportMap } from \"../optimizeImportMap.js\"\nimport { resolvePackageMain } from \"./resolvePackageMain.js\"\nimport { visitPackageImportMap } from \"./visitPackageImportMap.js\"\nimport { visitPackageExports } from \"./visitPackageExports.js\"\nimport { createFindNodeModulePackage } from \"./node-module-resolution.js\"\n\nexport const getImportMapFromPackageFiles = async ({\n // nothing is actually listening for this cancellationToken for now\n // it's not very important but it would be better to register on it\n // an stops what we are doing if asked to do so\n // cancellationToken = createCancellationTokenForProcess(),\n logger,\n warn,\n projectDirectoryUrl,\n projectPackageDevDependenciesIncluded = process.env.NODE_ENV !== \"production\",\n packagesExportsPreference = [\"import\", \"browser\"],\n packagesExportsIncluded = true,\n packagesManualOverrides = {},\n packageIncludedPredicate = () => true,\n}) => {\n projectDirectoryUrl = assertAndNormalizeDirectoryUrl(projectDirectoryUrl)\n\n const projectPackageFileUrl = resolveUrl(\"./package.json\", projectDirectoryUrl)\n const findNodeModulePackage = createFindNodeModulePackage(packagesManualOverrides)\n\n const imports = {}\n const scopes = {}\n const addMapping = ({ scope, from, to }) => {\n if (scope) {\n // when a package says './' maps to './'\n // we must add something to say if we are already inside the package\n // no need to ensure leading slash are scoped to the package\n if (from === \"./\" && to === scope) {\n addMapping({\n scope,\n from: scope,\n to: scope,\n })\n const packageName = scope.slice(scope.lastIndexOf(\"node_modules/\") + `node_modules/`.length)\n addMapping({\n scope,\n from: packageName,\n to: scope,\n })\n }\n\n scopes[scope] = {\n ...(scopes[scope] || {}),\n [from]: to,\n }\n } else {\n // we could think it's useless to remap from with to\n // however it can be used to ensure a weaker remapping\n // does not win over this specific file or folder\n if (from === to) {\n /**\n * however remapping '/' to '/' is truly useless\n * moreover it would make wrapImportMap create something like\n * {\n * imports: {\n * \"/\": \"/.dist/best/\"\n * }\n * }\n * that would append the wrapped folder twice\n * */\n if (from === \"/\") return\n }\n imports[from] = to\n }\n }\n\n const seen = {}\n const markPackageAsSeen = (packageFileUrl, importerPackageFileUrl) => {\n if (packageFileUrl in seen) {\n seen[packageFileUrl].push(importerPackageFileUrl)\n } else {\n seen[packageFileUrl] = [importerPackageFileUrl]\n }\n }\n const packageIsSeen = (packageFileUrl, importerPackageFileUrl) => {\n return packageFileUrl in seen && seen[packageFileUrl].includes(importerPackageFileUrl)\n }\n\n const visit = async ({\n packageFileUrl,\n packageName,\n packageJsonObject,\n importerPackageFileUrl,\n importerPackageJsonObject,\n includeDevDependencies,\n }) => {\n if (!packageIncludedPredicate({ packageName, packageFileUrl, packageJsonObject })) {\n return\n }\n\n await visitDependencies({\n packageFileUrl,\n packageJsonObject,\n includeDevDependencies,\n })\n await visitPackage({\n packageFileUrl,\n packageName,\n packageJsonObject,\n importerPackageFileUrl,\n importerPackageJsonObject,\n })\n }\n\n const visitPackage = async ({\n packageFileUrl,\n packageName,\n packageJsonObject,\n importerPackageFileUrl,\n }) => {\n const packageInfo = computePackageInfo({\n packageFileUrl,\n packageName,\n importerPackageFileUrl,\n })\n\n await visitPackageMain({\n packageFileUrl,\n packageName,\n packageJsonObject,\n packageInfo,\n })\n\n const {\n importerIsRoot,\n importerRelativeUrl,\n packageIsRoot,\n packageDirectoryRelativeUrl,\n // packageDirectoryUrl,\n // packageDirectoryUrlExpected,\n } = packageInfo\n\n const addImportMapForPackage = (importMap) => {\n if (packageIsRoot) {\n const { imports = {}, scopes = {} } = importMap\n Object.keys(imports).forEach((from) => {\n addMapping({\n from,\n to: imports[from],\n })\n })\n Object.keys(scopes).forEach((scope) => {\n const scopeMappings = scopes[scope]\n Object.keys(scopeMappings).forEach((key) => {\n addMapping({\n scope,\n from: key,\n to: scopeMappings[key],\n })\n })\n })\n return\n }\n\n const { imports = {}, scopes = {} } = importMap\n const scope = `./${packageDirectoryRelativeUrl}`\n Object.keys(imports).forEach((from) => {\n const to = imports[from]\n const toMoved = moveMappingValue(to, packageFileUrl, projectDirectoryUrl)\n addMapping({\n scope,\n from,\n to: toMoved,\n })\n })\n Object.keys(scopes).forEach((scope) => {\n const scopeMappings = scopes[scope]\n const scopeMoved = moveMappingValue(scope, packageFileUrl, projectDirectoryUrl)\n Object.keys(scopeMappings).forEach((key) => {\n const to = scopeMappings[key]\n const toMoved = moveMappingValue(to, packageFileUrl, projectDirectoryUrl)\n addMapping({\n scope: scopeMoved,\n from: key,\n to: toMoved,\n })\n })\n })\n }\n\n const addMappingsForPackageAndImporter = (mappings) => {\n if (packageIsRoot) {\n Object.keys(mappings).forEach((from) => {\n const to = mappings[from]\n addMapping({\n from,\n to,\n })\n })\n return\n }\n\n if (importerIsRoot) {\n // own package mappings available to himself\n Object.keys(mappings).forEach((from) => {\n const to = mappings[from]\n addMapping({\n scope: `./${packageDirectoryRelativeUrl}`,\n from,\n to,\n })\n addMapping({ from, to })\n })\n\n // if importer is root no need to make package mappings available to the importer\n // because they are already on top level mappings\n return\n }\n\n Object.keys(mappings).forEach((from) => {\n const to = mappings[from]\n // own package exports available to himself\n addMapping({\n scope: `./${packageDirectoryRelativeUrl}`,\n from,\n to,\n })\n // now make package exports available to the importer\n // here if the importer is himself we could do stuff\n // we should even handle the case earlier to prevent top level remapping\n addMapping({\n scope: `./${importerRelativeUrl}`,\n from,\n to,\n })\n })\n }\n\n const importsFromPackageField = await visitPackageImportMap({\n warn,\n packageFileUrl,\n packageJsonObject,\n projectDirectoryUrl,\n })\n addImportMapForPackage(importsFromPackageField)\n\n if (packagesExportsIncluded && \"exports\" in packageJsonObject) {\n const mappingsFromPackageExports = {}\n visitPackageExports({\n warn,\n packageFileUrl,\n packageJsonObject,\n packageName,\n projectDirectoryUrl,\n packagesExportsPreference,\n onExport: ({ key, value }) => {\n const from = key\n const to = value\n\n if (from.indexOf(\"*\") === -1) {\n mappingsFromPackageExports[from] = to\n return\n }\n\n if (\n from.endsWith(\"/*\") &&\n to.endsWith(\"/*\") &&\n // ensure ends with '*' AND there is only one '*' occurence\n to.indexOf(\"*\") === to.length - 1\n ) {\n const fromWithouTrailingStar = from.slice(0, -1)\n const toWithoutTrailingStar = to.slice(0, -1)\n mappingsFromPackageExports[fromWithouTrailingStar] = toWithoutTrailingStar\n return\n }\n\n warn(\n createExportsWildcardIgnoredWarning({\n key,\n value,\n packageFileUrl,\n }),\n )\n },\n })\n addMappingsForPackageAndImporter(mappingsFromPackageExports)\n }\n }\n\n const visitPackageMain = async ({\n packageFileUrl,\n packageName,\n packageJsonObject,\n packageInfo: {\n importerIsRoot,\n importerRelativeUrl,\n packageDirectoryUrl,\n packageDirectoryUrlExpected,\n },\n }) => {\n const mainFileUrl = await resolvePackageMain({\n warn,\n packagesExportsPreference,\n packageFileUrl,\n packageJsonObject,\n })\n\n // it's possible to have no main\n // like { main: \"\" } in package.json\n // or a main that does not lead to an actual file\n if (mainFileUrl === null) {\n return\n }\n\n const mainFileRelativeUrl = urlToRelativeUrl(mainFileUrl, projectDirectoryUrl)\n const from = packageName\n const to = `./${mainFileRelativeUrl}`\n\n if (importerIsRoot) {\n addMapping({ from, to })\n } else {\n addMapping({\n scope: `./${importerRelativeUrl}`,\n from,\n to,\n })\n }\n if (packageDirectoryUrl !== packageDirectoryUrlExpected) {\n addMapping({\n scope: `./${importerRelativeUrl}`,\n from,\n to,\n })\n }\n }\n\n const visitDependencies = async ({\n packageFileUrl,\n packageJsonObject,\n includeDevDependencies,\n }) => {\n const dependencyMap = packageDependenciesFromPackageObject(packageJsonObject, {\n includeDevDependencies,\n })\n\n await Promise.all(\n Object.keys(dependencyMap).map(async (dependencyName) => {\n const dependencyInfo = dependencyMap[dependencyName]\n await visitDependency({\n packageFileUrl,\n packageJsonObject,\n dependencyName,\n dependencyInfo,\n })\n }),\n )\n }\n\n const visitDependency = async ({\n packageFileUrl,\n packageJsonObject,\n dependencyName,\n dependencyInfo,\n }) => {\n const dependencyData = await findDependency({\n packageFileUrl,\n dependencyName,\n })\n if (!dependencyData) {\n const cannotFindPackageWarning = createCannotFindPackageWarning({\n dependencyName,\n dependencyInfo,\n packageFileUrl,\n })\n if (dependencyInfo.isOptional) {\n logger.debug(cannotFindPackageWarning.message)\n } else {\n warn(cannotFindPackageWarning)\n }\n\n return\n }\n if (dependencyData.syntaxError) {\n return\n }\n\n const {\n packageFileUrl: dependencyPackageFileUrl,\n packageJsonObject: dependencyPackageJsonObject,\n } = dependencyData\n\n if (packageIsSeen(dependencyPackageFileUrl, packageFileUrl)) {\n return\n }\n markPackageAsSeen(dependencyPackageFileUrl, packageFileUrl)\n await visit({\n packageFileUrl: dependencyPackageFileUrl,\n packageName: dependencyName,\n packageJsonObject: dependencyPackageJsonObject,\n importerPackageFileUrl: packageFileUrl,\n importerPackageJsonObject: packageJsonObject,\n })\n }\n\n const computePackageInfo = ({ packageFileUrl, packageName, importerPackageFileUrl }) => {\n const importerIsRoot = importerPackageFileUrl === projectPackageFileUrl\n\n const importerPackageDirectoryUrl = resolveUrl(\"./\", importerPackageFileUrl)\n\n const importerRelativeUrl = urlToRelativeUrl(importerPackageDirectoryUrl, projectDirectoryUrl)\n\n const packageIsRoot = packageFileUrl === projectPackageFileUrl\n\n const packageDirectoryUrl = resolveUrl(\"./\", packageFileUrl)\n\n const packageDirectoryUrlExpected = `${importerPackageDirectoryUrl}node_modules/${packageName}/`\n\n const packageDirectoryRelativeUrl = urlToRelativeUrl(packageDirectoryUrl, projectDirectoryUrl)\n\n return {\n importerIsRoot,\n importerRelativeUrl,\n packageIsRoot,\n packageDirectoryUrl,\n packageDirectoryUrlExpected,\n packageDirectoryRelativeUrl,\n }\n }\n\n const dependenciesCache = {}\n const findDependency = ({ packageFileUrl, dependencyName }) => {\n if (packageFileUrl in dependenciesCache === false) {\n dependenciesCache[packageFileUrl] = {}\n }\n if (dependencyName in dependenciesCache[packageFileUrl]) {\n return dependenciesCache[packageFileUrl][dependencyName]\n }\n const dependencyPromise = findNodeModulePackage({\n projectDirectoryUrl,\n packageFileUrl,\n dependencyName,\n })\n dependenciesCache[packageFileUrl][dependencyName] = dependencyPromise\n return dependencyPromise\n }\n\n const projectPackageJsonObject = await readFile(projectPackageFileUrl, { as: \"json\" })\n const importerPackageFileUrl = projectPackageFileUrl\n markPackageAsSeen(projectPackageFileUrl, importerPackageFileUrl)\n\n const packageName = projectPackageJsonObject.name\n if (typeof packageName !== \"string\") {\n warn(\n createPackageNameMustBeAStringWarning({\n packageName,\n packageFileUrl: projectPackageFileUrl,\n }),\n )\n return {}\n }\n\n await visit({\n packageFileUrl: projectPackageFileUrl,\n packageName: projectPackageJsonObject.name,\n packageJsonObject: projectPackageJsonObject,\n importerPackageFileUrl,\n importerPackageJsonObject: null,\n includeDevDependencies: projectPackageDevDependenciesIncluded,\n })\n\n return optimizeImportMap({ imports, scopes })\n}\n\nconst packageDependenciesFromPackageObject = (packageObject, { includeDevDependencies }) => {\n const packageDependencies = {}\n\n const { dependencies = {} } = packageObject\n // https://npm.github.io/using-pkgs-docs/package-json/types/optionaldependencies.html\n const { optionalDependencies = {} } = packageObject\n Object.keys(dependencies).forEach((dependencyName) => {\n packageDependencies[dependencyName] = {\n type: \"dependency\",\n isOptional: dependencyName in optionalDependencies,\n versionPattern: dependencies[dependencyName],\n }\n })\n\n const { peerDependencies = {} } = packageObject\n const { peerDependenciesMeta = {} } = packageObject\n Object.keys(peerDependencies).forEach((dependencyName) => {\n packageDependencies[dependencyName] = {\n type: \"peerDependency\",\n versionPattern: peerDependencies[dependencyName],\n isOptional:\n dependencyName in peerDependenciesMeta && peerDependenciesMeta[dependencyName].optional,\n }\n })\n\n if (includeDevDependencies) {\n const { devDependencies = {} } = packageObject\n Object.keys(devDependencies).forEach((dependencyName) => {\n if (!packageDependencies.hasOwnProperty(dependencyName)) {\n packageDependencies[dependencyName] = {\n type: \"devDependency\",\n versionPattern: devDependencies[dependencyName],\n }\n }\n })\n }\n\n return packageDependencies\n}\n\nconst moveMappingValue = (address, from, to) => {\n const url = resolveUrl(address, from)\n const relativeUrl = urlToRelativeUrl(url, to)\n if (relativeUrl.startsWith(\"../\")) {\n return relativeUrl\n }\n if (relativeUrl.startsWith(\"./\")) {\n return relativeUrl\n }\n if (/^[a-zA-Z]{2,}:/.test(relativeUrl)) {\n // has sheme\n return relativeUrl\n }\n return `./${relativeUrl}`\n}\n\nconst createExportsWildcardIgnoredWarning = ({ key, value, packageFileUrl }) => {\n return {\n code: \"EXPORTS_WILDCARD\",\n message: `Ignoring export using \"*\" because it is not supported by importmap.\n--- key ---\n${key}\n--- value ---\n${value}\n--- package.json path ---\n${urlToFileSystemPath(packageFileUrl)}\n--- see also ---\nhttps://github.com/WICG/import-maps/issues/232`,\n }\n}\n\nconst createPackageNameMustBeAStringWarning = ({ packageName, packageFileUrl }) => {\n return {\n code: \"PACKAGE_NAME_MUST_BE_A_STRING\",\n message: `package name field must be a string\n--- package name field ---\n${packageName}\n--- package.json file path ---\n${packageFileUrl}`,\n }\n}\n\nconst createCannotFindPackageWarning = ({ dependencyName, dependencyInfo, packageFileUrl }) => {\n const dependencyIsOptional = dependencyInfo.isOptional\n const dependencyType = dependencyInfo.type\n const dependencyVersionPattern = dependencyInfo.versionPattern\n return {\n code: \"CANNOT_FIND_PACKAGE\",\n message: createDetailedMessage(\n dependencyIsOptional\n ? `cannot find an optional ${dependencyType}.`\n : `cannot find a ${dependencyType}.`,\n {\n [dependencyType]: `${dependencyName}@${dependencyVersionPattern}`,\n \"required by\": urlToFileSystemPath(packageFileUrl),\n },\n ),\n }\n}\n", + "import { sortImportMap } from \"@jsenv/import-map\"\nimport { createLogger } from \"@jsenv/logger\"\nimport { getImportMapFromJsFiles } from \"./internal/from-js/getImportMapFromJsFiles.js\"\nimport { getImportMapFromPackageFiles } from \"./internal/from-package/getImportMapFromPackageFiles.js\"\n\nexport const getImportMapFromProjectFiles = async ({\n logLevel,\n projectDirectoryUrl,\n runtime = \"browser\",\n moduleFormat = \"esm\",\n dev = false,\n jsFiles = true,\n removeUnusedMappings = !dev,\n magicExtensions,\n onWarn = (warning, warn) => {\n warn(warning)\n },\n ...rest\n}) => {\n const packagesExportsPreference = [\n ...(moduleFormatPreferences[moduleFormat] || [moduleFormat]),\n ...(runtimeExportsPreferences[runtime] || [runtime]),\n ...(dev ? \"development\" : \"production\"),\n ]\n\n const logger = createLogger({ logLevel })\n const warn = (warning) => {\n onWarn(warning, () => {\n logger.warn(`\\n${warning.message}\\n`)\n })\n }\n\n // At this point, importmap is relative to the project directory url\n let importMapFromPackageFiles = await getImportMapFromPackageFiles({\n logger,\n warn,\n projectDirectoryUrl,\n packagesExportsPreference,\n projectPackageDevDependenciesIncluded: dev,\n ...rest,\n })\n importMapFromPackageFiles = sortImportMap(importMapFromPackageFiles)\n if (!jsFiles) {\n return importMapFromPackageFiles\n }\n\n let importMapFromJsFiles = await getImportMapFromJsFiles({\n warn,\n importMap: importMapFromPackageFiles,\n removeUnusedMappings,\n projectDirectoryUrl,\n magicExtensions,\n packagesExportsPreference,\n runtime,\n })\n importMapFromJsFiles = sortImportMap(importMapFromJsFiles)\n return importMapFromJsFiles\n}\n\nconst runtimeExportsPreferences = {\n browser: [\"browser\"],\n node: [\"node\"],\n}\n\nconst moduleFormatPreferences = {\n esm: [\"import\"],\n cjs: [\"require\"],\n}\n", "import { assertAndNormalizeDirectoryUrl, resolveUrl, readFile } from \"@jsenv/util\"\nimport { moveImportMap, sortImportMap } from \"@jsenv/import-map\"\n\nexport const getImportMapFromFile = async ({ projectDirectoryUrl, importMapFileRelativeUrl }) => {\n projectDirectoryUrl = assertAndNormalizeDirectoryUrl(projectDirectoryUrl)\n\n const importmapFileUrl = resolveUrl(importMapFileRelativeUrl, projectDirectoryUrl)\n const importmap = await readFile(importmapFileUrl, { as: \"json\" })\n\n // ensure the importmap is now relative to the project directory url\n // we do that because writeImportMapFile expect all importmap\n // to be relative to the projectDirectoryUrl\n const importmapFakeRootUrl = resolveUrl(\"whatever.importmap\", projectDirectoryUrl)\n const importmapRelativeToProject = moveImportMap(\n importmap,\n importmapFileUrl,\n importmapFakeRootUrl,\n )\n\n return sortImportMap(importmapRelativeToProject)\n}\n", "export const importMapToVsCodeConfigPaths = ({ imports = {} }) => {\n const paths = {}\n\n Object.keys(imports).forEach((importKey) => {\n const importValue = imports[importKey]\n\n let key\n if (importKey.endsWith(\"/\")) {\n key = `${importKey}*`\n } else {\n key = importKey\n }\n\n const importValueArray = typeof importValue === \"string\" ? [importValue] : importValue\n const candidatesForPath = importValueArray.map((importValue) => {\n if (importValue.endsWith(\"/\")) {\n return `${importValue}*`\n }\n return importValue\n })\n\n if (key in paths) {\n paths[key] = [...paths[key], ...candidatesForPath]\n } else {\n paths[key] = candidatesForPath\n }\n })\n\n return paths\n}\n", "import {\n resolveUrl,\n urlToFileSystemPath,\n assertAndNormalizeDirectoryUrl,\n writeFile,\n} from \"@jsenv/util\"\nimport { composeTwoImportMaps } from \"@jsenv/import-map\"\nimport { importMapToVsCodeConfigPaths } from \"./internal/importMapToVsCodeConfigPaths.js\"\n\nexport const writeImportMapFile = async (\n importMapInputs = [],\n {\n projectDirectoryUrl,\n\n importMapFile = true, // in case someone wants the importmap but not write it on filesystem\n importMapFileRelativeUrl = \"./import-map.importmap\",\n importMapFileLog = true,\n\n jsConfigFile = false, // not yet documented, makes vscode aware of the import remapping\n jsConfigFileLog = true,\n jsConfigLeadingSlash = false,\n jsConfigBase = {},\n },\n) => {\n projectDirectoryUrl = assertAndNormalizeDirectoryUrl(projectDirectoryUrl)\n\n if (importMapInputs.length === 0) {\n console.warn(`importMapInputs is empty, the generated importmap will be empty`)\n }\n\n const importMaps = await Promise.all(importMapInputs)\n\n const importMap = importMaps.reduce((previous, current) => {\n return composeTwoImportMaps(previous, current)\n }, {})\n\n if (importMapFile) {\n const importMapFileUrl = resolveUrl(importMapFileRelativeUrl, projectDirectoryUrl)\n await writeFile(importMapFileUrl, JSON.stringify(importMap, null, \" \"))\n if (importMapFileLog) {\n console.info(`-> ${urlToFileSystemPath(importMapFileUrl)}`)\n }\n }\n if (jsConfigFile) {\n const jsConfigFileUrl = resolveUrl(\"./jsconfig.json\", projectDirectoryUrl)\n try {\n const jsConfig = {\n compilerOptions: {\n baseUrl: \".\",\n ...jsConfigBase,\n paths: {\n ...(jsConfigLeadingSlash ? { \"/*\": [\"./*\"] } : {}),\n ...importMapToVsCodeConfigPaths(importMap),\n },\n },\n }\n await writeFile(jsConfigFileUrl, JSON.stringify(jsConfig, null, \" \"))\n if (jsConfigFileLog) {\n console.info(`-> ${urlToFileSystemPath(jsConfigFileUrl)}`)\n }\n } catch (e) {\n if (e.code !== \"ENOENT\") {\n throw e\n }\n }\n }\n\n return importMap\n}\n" @@ -46,8 +46,7 @@ "names": [ "memoizeAsyncFunctionByUrl", "fn", - "map", - "WeakMap", + "cache", "memoizeAsyncFunction", "getMemoryEntryFromArguments", "url", @@ -60,6 +59,7 @@ "specifier", "importer", "specifierCacheForImporter", + "memoized", "args", "memoryEntry", "promiseFromMemory", @@ -69,6 +69,8 @@ "value", "error", "e", + "isInMemory", + "Boolean", "Promise", "res", "rej", @@ -150,6 +152,7 @@ "Math", "floor", "ceil", + "map", "lineSource", "index", "lineNumber", @@ -201,7 +204,6 @@ "urlCandidate", "stats", "predicate", - "Boolean", "BARE_SPECIFIER_ERROR", "getImportMapFromJsFiles", "warn", @@ -223,8 +225,10 @@ "resolveImport", "defaultExtension", "onImportMapping", + "urlToRelativeUrl", + "startsWith", "createBareSpecifierError", - "visitFile", + "resolveFileSystemUrl", "importedBy", "gotBareSpecifierError", "fileUrlOnFileSystem", @@ -235,18 +239,21 @@ "packageDirectoryUrlFromUrl", "packageFileUrl", "autoMapping", - "urlToRelativeUrl", "formatAutoMappingSpecifierWarning", "closestPackageDirectoryUrl", "closestPackageObject", - "visitFileContent", - "readFileContent", + "visitFile", + "dependencies", "all", "Object", "keys", "specifierInfo", - "visitFileMemoized", + "dependencyUrlOnFileSystem", + "dependenciesToVisit", + "filter", + "dependency", "projectPackageObject", + "projectMainFileUrlOnFileSystem", "name", "exports", "importsUsed", @@ -254,6 +261,8 @@ "scopesUsed", "mappingsUsed", "scopedMappings", + "sortImportMap", + "composeTwoImportMaps", "relativeUrl", "lastNodeModulesDirectoryStartIndex", "lastIndexOf", @@ -263,7 +272,6 @@ "remainingDirectories", "importerExtension", "magicExtensionsWithoutImporterExtension", - "filter", "ext", "code", "createDetailedMessage", @@ -295,7 +303,6 @@ "main", "mainFileRelativeUrl", "mainFileUrlFirstCandidate", - "startsWith", "createPackageMainFileMustBeRelativeWarning", "mainFileUrl", "createPackageMainFileNotFoundWarning", @@ -427,7 +434,6 @@ "projectPackageJsonObject", "createPackageNameMustBeAStringWarning", "packageDependencies", - "dependencies", "optionalDependencies", "versionPattern", "peerDependencies", @@ -451,9 +457,7 @@ "runtimeExportsPreferences", "createLogger", "importMapFromPackageFiles", - "sortImportMap", "importMapFromJsFiles", - "composeTwoImportMaps", "esm", "cjs", "getImportMapFromFile", @@ -486,5 +490,5 @@ "compilerOptions", "baseUrl" ], - "mappings": ";;;;;;;;;;AAAO,MAAMA,yBAAyB,GAAIC,EAAD,IAAQ;AAC/C,QAAMC,GAAG,GAAG,IAAIC,OAAJ,EAAZ;AACA,SAAOC,oBAAoB,CAACH,EAAD,EAAK;AAC9BI,IAAAA,2BAA2B,EAAE,CAAC,CAACC,GAAD,CAAD,KAAW;AACtC,aAAO;AACLC,QAAAA,GAAG,EAAE,MAAM;AACT,iBAAOL,GAAG,CAACK,GAAJ,CAAQD,GAAR,CAAP;AACD,SAHI;AAILE,QAAAA,GAAG,EAAGC,OAAD,IAAa;AAChBP,UAAAA,GAAG,CAACM,GAAJ,CAAQF,GAAR,EAAaG,OAAb;AACD,SANI;AAOLC,QAAAA,MAAM,EAAE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Ac,MAAKhY,wBAAmB,CAACiY,eAAD,CAAkB,EAAxD;AACD;AACF,KAfD,CAeE,OAAOja,CAAP,EAAU;AACV,UAAIA,CAAC,CAAC6M,IAAF,KAAW,QAAf,EAAyB;AACvB,cAAM7M,CAAN;AACD;AACF;AACF;;AAED,SAAO2I,WAAP;AACD;;;;;;" } \ No newline at end of file diff --git a/package.json b/package.json index a761b14b..28e587bb 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@jsenv/node-module-import-map", - "version": "13.0.0-alpha.3", + "version": "13.0.0-alpha.5", "description": "Generate importmap for node_modules.", "license": "MIT", "repository": { From 8f5c81654f87c79d945613e85a412537677ca5e8 Mon Sep 17 00:00:00 2001 From: Damien Maillard Date: Fri, 12 Mar 2021 17:43:40 +0100 Subject: [PATCH 36/36] 13.0.0 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 28e587bb..0e60791c 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@jsenv/node-module-import-map", - "version": "13.0.0-alpha.5", + "version": "13.0.0", "description": "Generate importmap for node_modules.", "license": "MIT", "repository": {