@jsenv/import-map
Advanced tools
Comparing version 6.9.2 to 6.10.0
{ | ||
"name": "@jsenv/import-map", | ||
"version": "6.9.2", | ||
"version": "6.10.0", | ||
"description": "Helpers to implement importmaps.", | ||
@@ -31,33 +31,35 @@ "license": "MIT", | ||
"scripts": { | ||
"start-exploring": "node --no-warnings ./script/start-exploring/start-exploring.js", | ||
"test": "node --no-warnings --unhandled-rejections=strict ./script/test/test.js", | ||
"eslint-check": "node ./node_modules/eslint/bin/eslint.js .", | ||
"generate-import-map": "node ./script/generate-import-map/generate-import-map.js", | ||
"dist": "npm run generate-esmodule-build && npm run generate-commonjs-build", | ||
"generate-esmodule-build": "node ./script/generate-esmodule-build/generate-esmodule-build.js", | ||
"generate-commonjs-build": "node ./script/generate-commonjs-build/generate-commonjs-build.js", | ||
"start-exploring": "node ./script/start-exploring/start-exploring.js", | ||
"test": "node --unhandled-rejections=strict ./script/test/test.js", | ||
"test-with-coverage": "npm run test -- --coverage", | ||
"eslint-check": "node ./node_modules/eslint/bin/eslint.js .", | ||
"prettier-format": "node --no-warnings ./script/prettier-format/prettier-format.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", | ||
"upload-coverage": "node ./script/upload-coverage/upload-coverage.js", | ||
"generate-esmodule-bundle": "node ./script/generate-esmodule-bundle/generate-esmodule-bundle.js", | ||
"generate-commonjs-bundle": "node ./script/generate-commonjs-bundle/generate-commonjs-bundle.js", | ||
"generate-import-map": "node --no-warnings ./script/generate-import-map/generate-import-map.js", | ||
"dist": "npm run generate-esmodule-bundle && npm run generate-commonjs-bundle", | ||
"prepublishOnly": "node ./script/transform-package/remove-postinstall.js && npm run dist", | ||
"postpublish": "node ./script/transform-package/restore-postinstall.js" | ||
}, | ||
"dependencies": {}, | ||
"dependencies": { | ||
"@jsenv/logger": "4.0.0" | ||
}, | ||
"devDependencies": { | ||
"@jsenv/assert": "2.2.1", | ||
"@jsenv/assert": "2.2.3", | ||
"@jsenv/codecov-upload": "3.4.3", | ||
"@jsenv/core": "16.5.1", | ||
"@jsenv/eslint-config": "12.7.0", | ||
"@jsenv/core": "17.7.0", | ||
"@jsenv/eslint-config": "12.8.0", | ||
"@jsenv/github-release-package": "1.2.2", | ||
"@jsenv/node-module-import-map": "12.2.0", | ||
"@jsenv/package-publish": "1.5.1", | ||
"@jsenv/node-module-import-map": "12.3.0", | ||
"@jsenv/package-publish": "1.5.2", | ||
"@jsenv/prettier-check-project": "5.6.1", | ||
"eslint": "7.12.1", | ||
"playwright-chromium": "1.5.2", | ||
"playwright-firefox": "1.5.2", | ||
"playwright-webkit": "1.5.2", | ||
"prettier": "2.1.2" | ||
"eslint": "7.17.0", | ||
"playwright-chromium": "1.7.1", | ||
"playwright-firefox": "1.7.1", | ||
"playwright-webkit": "1.7.1", | ||
"prettier": "2.2.1" | ||
} | ||
} |
@@ -0,1 +1,2 @@ | ||
import { createDetailedMessage } from "@jsenv/logger" | ||
import { assertImportMap } from "./internal/assertImportMap.js" | ||
@@ -6,13 +7,33 @@ import { hasScheme } from "./internal/hasScheme.js" | ||
export const applyImportMap = ({ importMap, specifier, importer }) => { | ||
export const applyImportMap = ({ | ||
importMap, | ||
specifier, | ||
importer, | ||
formatImporterForError = (importer) => importer, | ||
}) => { | ||
assertImportMap(importMap) | ||
if (typeof specifier !== "string") { | ||
throw new TypeError(writeSpecifierMustBeAString({ specifier, importer })) | ||
throw new TypeError( | ||
createDetailedMessage("specifier must be a string.", { | ||
specifier, | ||
importer: formatImporterForError(importer), | ||
}), | ||
) | ||
} | ||
if (importer) { | ||
if (typeof importer !== "string") { | ||
throw new TypeError(writeImporterMustBeAString({ importer, specifier })) | ||
throw new TypeError( | ||
createDetailedMessage("importer must be a string.", { | ||
importer: formatImporterForError(importer), | ||
specifier, | ||
}), | ||
) | ||
} | ||
if (!hasScheme(importer)) { | ||
throw new Error(writeImporterMustBeAbsolute({ importer, specifier })) | ||
throw new Error( | ||
createDetailedMessage(`importer must be an absolute url.`, { | ||
importer: formatImporterForError(importer), | ||
specifier, | ||
}), | ||
) | ||
} | ||
@@ -50,3 +71,8 @@ } | ||
throw new Error(writeBareSpecifierMustBeRemapped({ specifier, importer })) | ||
throw new Error( | ||
createDetailedMessage(`Unmapped bare specifier.`, { | ||
specifier, | ||
importer: formatImporterForError(importer), | ||
}), | ||
) | ||
} | ||
@@ -79,25 +105,1 @@ | ||
} | ||
const writeSpecifierMustBeAString = ({ specifier, importer }) => `specifier must be a string. | ||
--- specifier --- | ||
${specifier} | ||
--- importer --- | ||
${importer}` | ||
const writeImporterMustBeAString = ({ importer, specifier }) => `importer must be a string. | ||
--- importer --- | ||
${importer} | ||
--- specifier --- | ||
${specifier}` | ||
const writeImporterMustBeAbsolute = ({ importer, specifier }) => `importer must be an absolute url. | ||
--- importer --- | ||
${importer} | ||
--- specifier --- | ||
${specifier}` | ||
const writeBareSpecifierMustBeRemapped = ({ specifier, importer }) => `Unmapped bare specifier. | ||
--- specifier --- | ||
${specifier} | ||
--- importer --- | ||
${importer}` |
@@ -6,6 +6,12 @@ import { urlToPathname } from "./internal/urlToPathname.js" | ||
export const resolveImport = ({ specifier, importer, importMap, defaultExtension = true }) => { | ||
export const resolveImport = ({ | ||
specifier, | ||
importer, | ||
importMap, | ||
defaultExtension = true, | ||
formatImporterForError, | ||
}) => { | ||
return applyDefaultExtension({ | ||
url: importMap | ||
? applyImportMap({ importMap, specifier, importer }) | ||
? applyImportMap({ importMap, specifier, importer, formatImporterForError }) | ||
: resolveUrl(specifier, importer), | ||
@@ -12,0 +18,0 @@ importer, |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
186786
1
2063
+ Added@jsenv/logger@4.0.0
+ Added@jsenv/logger@4.0.0(transitive)