diff --git a/deploy/createTypesPackages.mjs b/deploy/createTypesPackages.mjs index 7f6507f13..4234bf763 100644 --- a/deploy/createTypesPackages.mjs +++ b/deploy/createTypesPackages.mjs @@ -4,22 +4,21 @@ // prettier-ignore export const packages = [ - { - name: "@types/web", - description: "Types for the DOM, and other web technologies in browsers", - readme: "./readmes/web.md", - files: [ - { from: "../generated/dom.generated.d.ts", to: "index.d.ts" }, - { from: "../generated/dom.iterable.generated.d.ts", to: "index.iterable.d.ts" } - ], - }, - ]; + { + name: "@types/web", + description: "Types for the DOM, and other web technologies in browsers", + readme: "./readmes/web.md", + files: [ + { from: "../generated/dom.generated.d.ts", to: "index.d.ts" }, + { from: "../generated/dom.iterable.generated.d.ts", to: "index.iterable.d.ts" } + ], + }, +]; // Note: You can add 'version: "1.0.0"' to a package above // to set the major or minor, otherwise it will always bump // the patch. -import { join, dirname } from "path"; import fs from "fs"; import fetch from "node-fetch"; import { fileURLToPath } from "url"; @@ -28,43 +27,40 @@ import pkg from "prettier"; const { format } = pkg; import { execSync } from "child_process"; -// eslint-disable-next-line @typescript-eslint/ban-ts-comment -// @ts-ignore -const __filename = fileURLToPath(import.meta.url); -const __dirname = dirname(__filename); - const go = async () => { const gitSha = execSync("git rev-parse HEAD").toString().trim().slice(0, 7); - const generatedDir = join(__dirname, "generated"); - const templateDir = join(__dirname, "template"); + const generatedDir = new URL("generated/", import.meta.url); + const templateDir = new URL("template/", import.meta.url); for (const pkg of packages) { const folderName = pkg.name.replace("@", "").replace("/", "-"); - const packagePath = join(generatedDir, folderName); + const packagePath = new URL(`${folderName}/`, generatedDir); - if (fs.existsSync(packagePath)) fs.rmSync(packagePath, { recursive: true }); + if (fs.existsSync(packagePath)) { + await fs.promises.rm(packagePath, { recursive: true }); + } fs.mkdirSync(packagePath, { recursive: true }); // Migrate in the template files for (const templateFile of fs.readdirSync(templateDir)) { if (templateFile.startsWith(".")) continue; - const templatedFile = join(templateDir, templateFile); - fs.copyFileSync(templatedFile, join(packagePath, templateFile)); + const templatedFile = new URL(templateFile, templateDir); + fs.copyFileSync(templatedFile, new URL(templateFile, packagePath)); } // Add the reference files in the config above pkg.files.forEach((fileRef) => { fs.copyFileSync( - join(__filename, "..", fileRef.from), - join(packagePath, fileRef.to) + new URL(fileRef.from, import.meta.url), + new URL(fileRef.to, packagePath) ); }); // Setup the files in the repo const newPkgJSON = await updatePackageJSON(packagePath, pkg, gitSha); - copyREADME(pkg, newPkgJSON, join(packagePath, "README.md")); + copyREADME(pkg, newPkgJSON, new URL("README.md", packagePath)); // Done console.log("Built:", pkg.name); @@ -72,7 +68,7 @@ const go = async () => { }; async function updatePackageJSON(packagePath, pkg, gitSha) { - const pkgJSONPath = join(packagePath, "package.json"); + const pkgJSONPath = new URL("package.json", packagePath); const packageText = fs.readFileSync(pkgJSONPath, "utf8"); const packageJSON = JSON.parse(packageText); packageJSON.name = pkg.name; @@ -107,7 +103,9 @@ async function updatePackageJSON(packagePath, pkg, gitSha) { fs.writeFileSync( pkgJSONPath, - format(JSON.stringify(packageJSON), { filepath: pkgJSONPath }) + format(JSON.stringify(packageJSON), { + filepath: fileURLToPath(pkgJSONPath), + }) ); return packageJSON; @@ -115,7 +113,7 @@ async function updatePackageJSON(packagePath, pkg, gitSha) { // Copies the README and adds some rudimentary templating to the file. function copyREADME(pkg, pkgJSON, writePath) { - let readme = fs.readFileSync(join(__filename, "..", pkg.readme), "utf-8"); + let readme = fs.readFileSync(new URL(pkg.readme, import.meta.url), "utf-8"); const htmlEncodedTag = encodeURIComponent(pkgJSON.name) + "%40" + pkgJSON.version; diff --git a/deploy/deployChangedPackages.mjs b/deploy/deployChangedPackages.mjs index 7333a44f5..580745b0b 100644 --- a/deploy/deployChangedPackages.mjs +++ b/deploy/deployChangedPackages.mjs @@ -6,18 +6,13 @@ // ones which have changed. import * as fs from "fs"; -import { join, dirname, basename } from "path"; -import { fileURLToPath } from "url"; +import { basename } from "path"; import { spawnSync, execSync } from "child_process"; import { Octokit } from "@octokit/core"; import printDiff from "print-diff"; import { generateChangelogFrom } from "../lib/changelog.js"; import { packages } from "./createTypesPackages.mjs"; - -// eslint-disable-next-line @typescript-eslint/ban-ts-comment -// @ts-ignore -const __filename = fileURLToPath(import.meta.url); -const __dirname = dirname(__filename); +import { fileURLToPath } from "node:url"; verify(); @@ -25,10 +20,11 @@ const uploaded = []; // Loop through generated packages, deploying versions for anything which has different // .d.ts files from the version available on npm. -const generatedDir = join(__dirname, "generated"); +const generatedDir = new URL("generated/", import.meta.url); for (const dirName of fs.readdirSync(generatedDir)) { console.log(`Looking at ${dirName}`); - const localPackageJSONPath = join(generatedDir, dirName, "package.json"); + const packageDir = new URL(`${dirName}/`, generatedDir); + const localPackageJSONPath = new URL("package.json", packageDir); const newTSConfig = fs.readFileSync(localPackageJSONPath, "utf-8"); const pkgJSON = JSON.parse(newTSConfig); @@ -37,7 +33,7 @@ for (const dirName of fs.readdirSync(generatedDir)) { const thisPackageMeta = packages.find((p) => p.name === pkgJSON.name); const dtsFiles = fs - .readdirSync(join(generatedDir, dirName)) + .readdirSync(packageDir) .filter((f) => f.endsWith(".d.ts")); /** @type {string[]} */ @@ -51,7 +47,7 @@ for (const dirName of fs.readdirSync(generatedDir)) { thisPackageMeta.files.find((f) => f.to === file).from ); - const generatedDTSPath = join(generatedDir, dirName, file); + const generatedDTSPath = new URL(file, packageDir); const generatedDTSContent = fs.readFileSync(generatedDTSPath, "utf8"); // This assumes we'll only _ever_ ship patches, which may change in the @@ -86,7 +82,7 @@ Assuming that this means we need to upload this package.`); if (upload) { if (process.env.NODE_AUTH_TOKEN) { const publish = spawnSync("npm", ["publish", "--access", "public"], { - cwd: join(generatedDir, dirName), + cwd: fileURLToPath(packageDir), stdio: "inherit", }); @@ -102,7 +98,7 @@ Assuming that this means we need to upload this package.`); } else { console.log( "Wanting to run: 'npm publish --access public' in " + - join(generatedDir, dirName) + fileURLToPath(packageDir) ); }