Skip to content

Commit

Permalink
chore: update Deno import maps on release
Browse files Browse the repository at this point in the history
  • Loading branch information
MichaelDeBoey committed May 19, 2022
1 parent 4c33095 commit 16df4d0
Showing 1 changed file with 56 additions and 0 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

0 comments on commit 16df4d0

Please sign in to comment.