|
| 1 | +import { globSync } from "glob"; |
| 2 | +import { execSync } from "node:child_process"; |
| 3 | +import { readFileSync } from "node:fs"; |
| 4 | + |
| 5 | +const { log, error } = console; |
| 6 | + |
| 7 | +/** |
| 8 | + * Parse ENVS |
| 9 | + */ |
| 10 | +const SHOULD_DEPRECATE_VERSIONS: boolean = |
| 11 | + process.env.DEPRECATE_VERSIONS === "true"; |
| 12 | +const FILTER_BY_PACKAGE_NAME: string = process.env.FILTER_BY_PACKAGE_NAME ?? ""; |
| 13 | + |
| 14 | +/** |
| 15 | + * Restricted tags that can be deprecated |
| 16 | + */ |
| 17 | +const DEPRECIABLE_TAGS: string[] = ["0.0.0-next", "0.0.0-pr", "0.0.0-rc"]; |
| 18 | + |
| 19 | +/** |
| 20 | + * Packages that are no longer published to npm |
| 21 | + * |
| 22 | + * TODO: Consider deprecating these packages |
| 23 | + */ |
| 24 | +const NO_LONGER_MAINTAINED_PACKAGES: string[] = [ |
| 25 | + "@fuel-ts/merkle-shared", |
| 26 | + "@fuel-ts/merklesum", |
| 27 | + "@fuel-ts/sparsemerkle", |
| 28 | + "@fuel-ts/providers", |
| 29 | + "@fuel-ts/example-contract", |
| 30 | + "@fuel-ts/wallet", |
| 31 | + "@fuel-ts/typechain-target-fuels", |
| 32 | + "@fuel-ts/testcases", |
| 33 | + "@fuel-ts/wordlists", |
| 34 | + "@fuel-ts/mnemonic", |
| 35 | + "@fuel-ts/signer", |
| 36 | + "@fuel-ts/hdwallet", |
| 37 | + "@fuel-ts/constants", |
| 38 | + "@fuel-ts/interfaces", |
| 39 | + "@fuel-ts/keystore", |
| 40 | + "@fuel-ts/wallet-manager", |
| 41 | + "@fuel-ts/predicate", |
| 42 | + "@fuel-ts/asm", |
| 43 | + "@fuel-ts/fuel-core", |
| 44 | + "@fuel-ts/forc", |
| 45 | +]; |
| 46 | + |
| 47 | +const MAINTAINED_PACKAGES: string[] = globSync("**/package.json") |
| 48 | + // Read in the package.json file |
| 49 | + .map((fileName) => { |
| 50 | + const packageJson = JSON.parse(readFileSync(fileName, "utf-8")); |
| 51 | + return { |
| 52 | + path: fileName, |
| 53 | + contents: packageJson, |
| 54 | + }; |
| 55 | + }) |
| 56 | + // Filter out private packages |
| 57 | + .filter((pkg) => !pkg.contents.private) |
| 58 | + .map((pkg) => pkg.contents.name); |
| 59 | + |
| 60 | +let packages: string[] = MAINTAINED_PACKAGES; |
| 61 | + |
| 62 | +// Only by using filter by package name, are we allowed to deprecate the no longer maintained packages |
| 63 | +if (FILTER_BY_PACKAGE_NAME !== "") { |
| 64 | + const allPackages = [ |
| 65 | + ...MAINTAINED_PACKAGES, |
| 66 | + ...NO_LONGER_MAINTAINED_PACKAGES, |
| 67 | + ]; |
| 68 | + packages = allPackages.filter((pkg) => pkg === FILTER_BY_PACKAGE_NAME); |
| 69 | + |
| 70 | + // Ensure that we have found a package |
| 71 | + if (packages.length === 0) { |
| 72 | + error(`❌ No package found with name: ${FILTER_BY_PACKAGE_NAME}`); |
| 73 | + process.exit(1); |
| 74 | + } |
| 75 | +} |
| 76 | + |
| 77 | +/** |
| 78 | + * Construct the depreciable package and versions |
| 79 | + */ |
| 80 | +const depreciablePackageAndVersions = packages.flatMap((pkgName) => |
| 81 | + DEPRECIABLE_TAGS.map((tag) => `${pkgName}@${tag}`), |
| 82 | +); |
| 83 | +log( |
| 84 | + "The following packages and versions will be deprecated\n", |
| 85 | + depreciablePackageAndVersions.join("\n"), |
| 86 | + "----------------------------------\n", |
| 87 | +); |
| 88 | + |
| 89 | +/** |
| 90 | + * Deprecate the packages and versions |
| 91 | + */ |
| 92 | +for await (const packageAndVersion of depreciablePackageAndVersions) { |
| 93 | + log(`Deprecating ${packageAndVersion}`); |
| 94 | + |
| 95 | + const dryRun = SHOULD_DEPRECATE_VERSIONS ? "" : "--dry-run "; |
| 96 | + const command = `npm deprecate ${packageAndVersion} ${dryRun}"Version no longer supported."`; |
| 97 | + |
| 98 | + try { |
| 99 | + const result = execSync(command); |
| 100 | + log(`✅ Deprecated ${packageAndVersion}`); |
| 101 | + log(result.toString()); |
| 102 | + } catch (err) { |
| 103 | + error(`❌ Error - unable to deprecate ${packageAndVersion}`); |
| 104 | + error(err); |
| 105 | + process.exit(1); |
| 106 | + } |
| 107 | + |
| 108 | + await new Promise((resolve) => { |
| 109 | + setTimeout(() => { |
| 110 | + resolve(true); |
| 111 | + }, 1000); |
| 112 | + }); |
| 113 | +} |
0 commit comments