Skip to content

Commit

Permalink
chore: update Deno import maps on release (remix-run#3225)
Browse files Browse the repository at this point in the history
* fix(templates/vercel): add `index.js.map` to `.gitignore` (remix-run#3216)

* Add `index.js.map` to `.gitignore`

In the Vercel template,  `/api/index.js.map` should also be ignored along with `/api/index.js`. Otherwise, that mapping file would be committed into version control, which is not desired.

* Sign CLA

* fix(scripts): Prevent publishing without a tag (remix-run#3223)

* move decisions

* docs: add `decisions/index.md` and frontmatter (remix-run#3226)

Co-authored-by: Pedro Cattori <[email protected]>
(cherry picked from commit e809206)

* docs(server-runtime): update link for deno server runtime package (remix-run#3228)

since it's now a proper package

* chore(templates): bring `deno` template in line with other templates (remix-run#3221)

* docs: fix links to decision docs (remix-run#3231)

* chore: update Deno import maps on release

Co-authored-by: Jiahao <[email protected]>
Co-authored-by: Chance Strickland <[email protected]>
Co-authored-by: Ryan Florence <[email protected]>
Co-authored-by: Logan McAnsh <[email protected]>
Co-authored-by: Pedro Cattori <[email protected]>
  • Loading branch information
6 people authored and justjavac committed Jun 11, 2022
1 parent 33a21fb commit 91d92f0
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 4 deletions.
56 changes: 56 additions & 0 deletions scripts/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,52 @@ async function updateDeploymentScriptVersion(nextVersion) {
);
}

/**
* @param {string} importSpecifier
* @returns {[string, string]} [packageName, importPath]
*/
const getPackageNameFromImportSpecifier = (importSpecifier) => {
if (importSpecifier.startsWith("@")) {
let [scope, pkg, ...path] = importSpecifier.split("/");
return [`${scope}/${pkg}`, path.join("/")];
}

let [pkg, ...path] = importSpecifier.split("/");
return [pkg, path.join("/")];
};
/**
* @param {string} importMapPath
* @param {string} nextVersion
*/
const updateDenoImportMap = async (importMapPath, nextVersion) => {
let { imports, ...json } = await jsonfile.readFile(importMapPath);
let remixPackagesFull = remixPackages.all.map(
(remixPackage) => `@remix-run/${remixPackage}`
);

let newImports = Object.fromEntries(
Object.entries(imports).map(([importName, path]) => {
let [packageName, importPath] =
getPackageNameFromImportSpecifier(importName);

return remixPackagesFull.includes(packageName)
? [
importName,
`https://esm.sh/${packageName}@${nextVersion}${
importPath ? `/${importPath}` : ""
}`,
]
: [importName, path];
})
);

return jsonfile.writeFile(
importMapPath,
{ ...json, imports: newImports },
{ spaces: 2 }
);
};

/**
* @param {string} nextVersion
*/
Expand All @@ -187,6 +233,16 @@ async function incrementRemixVersion(nextVersion) {
await updateRemixVersion(`remix-${name}`, nextVersion);
}

// Update version numbers in Deno's import maps
await Promise.all(
[
path.join(".vscode", "deno_resolve_npm_imports.json"),
path.join("templates", "deno", ".vscode", "resolve_npm_imports.json"),
].map((importMapPath) =>
updateDenoImportMap(path.join(rootDir, importMapPath), nextVersion)
)
);

// Update versions in the examples
await updateExamplesRemixVersion(nextVersion);

Expand Down
3 changes: 1 addition & 2 deletions templates/deno/.vscode/resolve_npm_imports.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@
"// Deno-only dependencies may be imported via URL imports (without using import maps).": "",

"imports": {
"// `@remix-run/deno` code is already a Deno module, so just get types for it directly from `node_modules/`": "",
"@remix-run/deno": "../node_modules/@remix-run/deno/index.ts",
"@remix-run/deno": "https://esm.sh/@remix-run/[email protected]",
"@remix-run/dev/server-build": "https://esm.sh/@remix-run/[email protected]/server-build",
"@remix-run/react": "https://esm.sh/@remix-run/[email protected]",
"react": "https://esm.sh/[email protected]",
Expand Down
4 changes: 2 additions & 2 deletions templates/deno/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
"dev": "remix build && run-p dev:*",
"dev:deno": "cross-env NODE_ENV=development deno run --unstable --watch --allow-net --allow-read --allow-env ./build/index.js",
"dev:remix": "remix watch",
"format": "deno fmt --ignore=node_modules,build,public/build",
"lint": "deno lint --ignore=node_modules,build,public/build",
"format": "deno fmt --ignore=node_modules",
"lint": "deno lint --ignore=node_modules",
"start": "cross-env NODE_ENV=production deno run --unstable --allow-net --allow-read --allow-env ./build/index.js"
},
"dependencies": {
Expand Down

0 comments on commit 91d92f0

Please sign in to comment.