Skip to content

Commit

Permalink
chore: update Deno import maps on release (#3255)
Browse files Browse the repository at this point in the history
Co-authored-by: Michaël De Boey <[email protected]>
  • Loading branch information
pcattori and MichaelDeBoey authored May 19, 2022
1 parent fb17436 commit 051b1bd
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 051b1bd

Please sign in to comment.