skuba 14.0.0 → 14.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -20,8 +20,4 @@ export type PatchConfig = {
|
|
|
20
20
|
dir?: string;
|
|
21
21
|
};
|
|
22
22
|
export type PatchFunction = (config: PatchConfig) => Promise<PatchReturnType>;
|
|
23
|
-
|
|
24
|
-
upgraded?: boolean;
|
|
25
|
-
};
|
|
26
|
-
export declare const upgradeSkuba: (mode: "lint" | "format", logger: Logger, additionalFlags?: string[]) => Promise<UpgradeSkubaResult>;
|
|
27
|
-
export {};
|
|
23
|
+
export declare const upgradeSkuba: (mode: "lint" | "format", logger: Logger, additionalFlags?: string[]) => Promise<InternalLintResult>;
|
|
@@ -175,8 +175,7 @@ const upgradeSkuba = async (mode, logger, additionalFlags = []) => {
|
|
|
175
175
|
logger.newline();
|
|
176
176
|
return {
|
|
177
177
|
ok: true,
|
|
178
|
-
fixable: false
|
|
179
|
-
upgraded: true
|
|
178
|
+
fixable: false
|
|
180
179
|
};
|
|
181
180
|
};
|
|
182
181
|
// Annotate the CommonJS export names for ESM import in node:
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../../../src/cli/lint/internalLints/upgrade/index.ts"],
|
|
4
|
-
"sourcesContent": ["import path from 'path';\n\nimport fs from 'fs-extra';\nimport type { ReadResult } from 'read-pkg-up';\nimport { gte, sort } from 'semver';\n\nimport { type Logger, log } from '../../../../utils/logging.js';\nimport { getConsumerManifest } from '../../../../utils/manifest.js';\nimport {\n type PackageManagerConfig,\n detectPackageManager,\n} from '../../../../utils/packageManager.js';\nimport { getSkubaVersion } from '../../../../utils/version.js';\nimport { formatPackage } from '../../../configure/processing/package.js';\nimport type { SkubaPackageJson } from '../../../init/writePackageJson.js';\nimport { getIgnores, shouldCommit } from '../../autofix.js';\nimport type { InternalLintResult } from '../../internal.js';\n\nimport { Git } from '@skuba-lib/api';\n\nexport type Patches = Patch[];\nexport type Patch = {\n apply: PatchFunction;\n description: string;\n};\nexport type PatchReturnType =\n | { result: 'apply' }\n | { result: 'skip'; reason?: string };\n\nexport type PatchConfig = {\n mode: 'format' | 'lint';\n manifest: ReadResult;\n packageManager: PackageManagerConfig;\n dir?: string;\n};\n\nexport type PatchFunction = (config: PatchConfig) => Promise<PatchReturnType>;\n\nconst getPatches = async (\n manifestVersion: string,\n): Promise<Map<string, Patches>> => {\n const patches = await fs.readdir(path.join(__dirname, 'patches'), {\n withFileTypes: true,\n });\n\n // The patches are sorted by the version they were added from.\n // Only return patches that are newer or equal to the current version.\n const patchesForVersion = sort(\n patches.flatMap((patch) =>\n // Is a directory rather than a JavaScript source file\n patch.isDirectory() &&\n // Has been added since the last patch run on the project\n gte(patch.name, manifestVersion)\n ? patch.name\n : [],\n ),\n );\n\n return new Map<string, Patches>(\n await Promise.all(\n patchesForVersion.map(async (version) => {\n const resolved = await resolvePatches(version);\n return [version, resolved] as const;\n }),\n ),\n );\n};\n\nconst fileExtensions = ['js', 'ts'];\n\n// Hack to allow our Jest environment/transform to resolve the patches\n// In normal scenarios this will resolve immediately after the .js import\nconst resolvePatches = async (version: string): Promise<Patches> => {\n for (const extension of fileExtensions) {\n try {\n // eslint-disable-next-line @typescript-eslint/no-unsafe-return, @typescript-eslint/no-unsafe-member-access\n return (await import(`./patches/${version}/index.${extension}`)).patches;\n } catch {\n // Ignore\n }\n }\n throw new Error(`Could not resolve patches for ${version}`);\n};\n\
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,kBAAiB;AAEjB,sBAAe;AAEf,oBAA0B;AAE1B,qBAAiC;AACjC,sBAAoC;AACpC,4BAGO;AACP,qBAAgC;AAChC,qBAA8B;AAE9B,qBAAyC;AAGzC,iBAAoB;AAoBpB,MAAM,aAAa,OACjB,oBACkC;AAClC,QAAM,UAAU,MAAM,gBAAAA,QAAG,QAAQ,YAAAC,QAAK,KAAK,WAAW,SAAS,GAAG;AAAA,IAChE,eAAe;AAAA,EACjB,CAAC;AAID,QAAM,wBAAoB;AAAA,IACxB,QAAQ;AAAA,MAAQ,CAAC;AAAA;AAAA,QAEf,MAAM,YAAY;AAAA,YAElB,mBAAI,MAAM,MAAM,eAAe,IAC3B,MAAM,OACN,CAAC;AAAA;AAAA,IACP;AAAA,EACF;AAEA,SAAO,IAAI;AAAA,IACT,MAAM,QAAQ;AAAA,MACZ,kBAAkB,IAAI,OAAO,YAAY;AACvC,cAAM,WAAW,MAAM,eAAe,OAAO;AAC7C,eAAO,CAAC,SAAS,QAAQ;AAAA,MAC3B,CAAC;AAAA,IACH;AAAA,EACF;AACF;AAEA,MAAM,iBAAiB,CAAC,MAAM,IAAI;AAIlC,MAAM,iBAAiB,OAAO,YAAsC;AAClE,aAAW,aAAa,gBAAgB;AACtC,QAAI;AAEF,cAAQ,MAAM,OAAO,aAAa,OAAO,UAAU,SAAS,KAAK;AAAA,IACnE,QAAQ;AAAA,IAER;AAAA,EACF;AACA,QAAM,IAAI,MAAM,iCAAiC,OAAO,EAAE;AAC5D;
|
|
4
|
+
"sourcesContent": ["import path from 'path';\n\nimport fs from 'fs-extra';\nimport type { ReadResult } from 'read-pkg-up';\nimport { gte, sort } from 'semver';\n\nimport { type Logger, log } from '../../../../utils/logging.js';\nimport { getConsumerManifest } from '../../../../utils/manifest.js';\nimport {\n type PackageManagerConfig,\n detectPackageManager,\n} from '../../../../utils/packageManager.js';\nimport { getSkubaVersion } from '../../../../utils/version.js';\nimport { formatPackage } from '../../../configure/processing/package.js';\nimport type { SkubaPackageJson } from '../../../init/writePackageJson.js';\nimport { getIgnores, shouldCommit } from '../../autofix.js';\nimport type { InternalLintResult } from '../../internal.js';\n\nimport { Git } from '@skuba-lib/api';\n\nexport type Patches = Patch[];\nexport type Patch = {\n apply: PatchFunction;\n description: string;\n};\nexport type PatchReturnType =\n | { result: 'apply' }\n | { result: 'skip'; reason?: string };\n\nexport type PatchConfig = {\n mode: 'format' | 'lint';\n manifest: ReadResult;\n packageManager: PackageManagerConfig;\n dir?: string;\n};\n\nexport type PatchFunction = (config: PatchConfig) => Promise<PatchReturnType>;\n\nconst getPatches = async (\n manifestVersion: string,\n): Promise<Map<string, Patches>> => {\n const patches = await fs.readdir(path.join(__dirname, 'patches'), {\n withFileTypes: true,\n });\n\n // The patches are sorted by the version they were added from.\n // Only return patches that are newer or equal to the current version.\n const patchesForVersion = sort(\n patches.flatMap((patch) =>\n // Is a directory rather than a JavaScript source file\n patch.isDirectory() &&\n // Has been added since the last patch run on the project\n gte(patch.name, manifestVersion)\n ? patch.name\n : [],\n ),\n );\n\n return new Map<string, Patches>(\n await Promise.all(\n patchesForVersion.map(async (version) => {\n const resolved = await resolvePatches(version);\n return [version, resolved] as const;\n }),\n ),\n );\n};\n\nconst fileExtensions = ['js', 'ts'];\n\n// Hack to allow our Jest environment/transform to resolve the patches\n// In normal scenarios this will resolve immediately after the .js import\nconst resolvePatches = async (version: string): Promise<Patches> => {\n for (const extension of fileExtensions) {\n try {\n // eslint-disable-next-line @typescript-eslint/no-unsafe-return, @typescript-eslint/no-unsafe-member-access\n return (await import(`./patches/${version}/index.${extension}`)).patches;\n } catch {\n // Ignore\n }\n }\n throw new Error(`Could not resolve patches for ${version}`);\n};\n\nexport const upgradeSkuba = async (\n mode: 'lint' | 'format',\n logger: Logger,\n additionalFlags: string[] = [],\n): Promise<InternalLintResult> => {\n const [currentVersion, manifest, packageManager] = await Promise.all([\n getSkubaVersion(),\n getConsumerManifest(),\n detectPackageManager(),\n ]);\n\n if (!manifest) {\n throw new Error('Could not find a package json for this project');\n }\n\n manifest.packageJson.skuba ??= { version: '1.0.0' };\n\n const manifestVersion = additionalFlags.includes('--force-apply-all-patches')\n ? '1.0.0'\n : (manifest.packageJson.skuba as SkubaPackageJson).version;\n\n // We are up to date, skip patches\n if (gte(manifestVersion, currentVersion)) {\n return { ok: true, fixable: false };\n }\n\n const patches = await getPatches(manifestVersion);\n // No patches to apply even if version out of date. Early exit to avoid unnecessary commits.\n if (patches.size === 0) {\n return { ok: true, fixable: false };\n }\n\n if (mode === 'lint') {\n const allPatches = Array.from(patches.values()).flat();\n const results = await Promise.all(\n allPatches.map(\n async ({ apply }) =>\n await apply({\n mode,\n manifest,\n packageManager,\n }),\n ),\n );\n\n // No patches are applicable. Early exit to avoid unnecessary commits.\n if (results.every(({ result }) => result === 'skip')) {\n return { ok: true, fixable: false };\n }\n\n logger.warn(\n `skuba has patches to apply. Run ${logger.bold(\n `${packageManager.print.exec} skuba format`,\n )} to run them.`,\n );\n\n return {\n ok: false,\n fixable: true,\n annotations: [\n {\n // package.json as likely skuba version has changed\n // TODO: locate the \"skuba\": {} config in the package.json and annotate on the version property\n path: manifest.path,\n message: `skuba has patches to apply. Run ${packageManager.print.exec} skuba format to run them.`,\n },\n ],\n };\n }\n\n logger.plain('Updating skuba...');\n\n const dir = process.cwd();\n let currentBranch;\n try {\n currentBranch = await Git.currentBranch({ dir });\n } catch {}\n\n const shouldCommitChanges = await shouldCommit({ currentBranch, dir });\n\n // Run these in series in case a subsequent patch relies on a previous patch\n for (const version of patches.keys()) {\n const patchesForVersion = patches.get(version);\n if (!patchesForVersion) {\n continue;\n }\n\n for (const { apply, description } of patchesForVersion) {\n const result = await apply({\n mode,\n manifest,\n packageManager,\n });\n logger.newline();\n if (result.result === 'skip') {\n logger.plain(\n `Patch skipped: ${description}${\n result.reason ? ` - ${result.reason}` : ''\n }`,\n );\n } else {\n logger.plain(`Patch applied: ${description}`);\n }\n }\n\n if (shouldCommitChanges) {\n // Only commit changes here, each version should have a separate commit and they should all be pushed together at the end\n const ref = await Git.commitAllChanges({\n dir,\n message: `Apply skuba ${version} patches`,\n\n ignore: await getIgnores(dir),\n });\n\n if (!ref) {\n log.warn('No autofixes detected.');\n return { ok: true, fixable: false };\n }\n }\n }\n\n const updatedManifest = await getConsumerManifest();\n if (!updatedManifest) {\n throw new Error('Could not find a package json for this project');\n }\n\n (updatedManifest.packageJson.skuba as SkubaPackageJson).version =\n currentVersion;\n\n const updatedPackageJson = await formatPackage(updatedManifest.packageJson);\n\n await fs.writeFile(updatedManifest.path, updatedPackageJson);\n logger.newline();\n logger.plain('skuba update complete.');\n logger.newline();\n\n return {\n ok: true,\n fixable: false,\n };\n};\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,kBAAiB;AAEjB,sBAAe;AAEf,oBAA0B;AAE1B,qBAAiC;AACjC,sBAAoC;AACpC,4BAGO;AACP,qBAAgC;AAChC,qBAA8B;AAE9B,qBAAyC;AAGzC,iBAAoB;AAoBpB,MAAM,aAAa,OACjB,oBACkC;AAClC,QAAM,UAAU,MAAM,gBAAAA,QAAG,QAAQ,YAAAC,QAAK,KAAK,WAAW,SAAS,GAAG;AAAA,IAChE,eAAe;AAAA,EACjB,CAAC;AAID,QAAM,wBAAoB;AAAA,IACxB,QAAQ;AAAA,MAAQ,CAAC;AAAA;AAAA,QAEf,MAAM,YAAY;AAAA,YAElB,mBAAI,MAAM,MAAM,eAAe,IAC3B,MAAM,OACN,CAAC;AAAA;AAAA,IACP;AAAA,EACF;AAEA,SAAO,IAAI;AAAA,IACT,MAAM,QAAQ;AAAA,MACZ,kBAAkB,IAAI,OAAO,YAAY;AACvC,cAAM,WAAW,MAAM,eAAe,OAAO;AAC7C,eAAO,CAAC,SAAS,QAAQ;AAAA,MAC3B,CAAC;AAAA,IACH;AAAA,EACF;AACF;AAEA,MAAM,iBAAiB,CAAC,MAAM,IAAI;AAIlC,MAAM,iBAAiB,OAAO,YAAsC;AAClE,aAAW,aAAa,gBAAgB;AACtC,QAAI;AAEF,cAAQ,MAAM,OAAO,aAAa,OAAO,UAAU,SAAS,KAAK;AAAA,IACnE,QAAQ;AAAA,IAER;AAAA,EACF;AACA,QAAM,IAAI,MAAM,iCAAiC,OAAO,EAAE;AAC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,gBAAAD,QAAG,UAAU,gBAAgB,MAAM,kBAAkB;AAC3D,SAAO,QAAQ;AACf,SAAO,MAAM,wBAAwB;AACrC,SAAO,QAAQ;AAEf,SAAO;AAAA,IACL,IAAI;AAAA,IACJ,SAAS;AAAA,EACX;AACF;",
|
|
6
6
|
"names": ["fs", "path"]
|
|
7
7
|
}
|
package/lib/cli/test/index.js
CHANGED
|
@@ -31,31 +31,10 @@ __export(test_exports, {
|
|
|
31
31
|
test: () => test
|
|
32
32
|
});
|
|
33
33
|
module.exports = __toCommonJS(test_exports);
|
|
34
|
-
var import_util = require("util");
|
|
35
|
-
var import_args = require("../../utils/args.js");
|
|
36
|
-
var import_env = require("../../utils/env.js");
|
|
37
34
|
var import_exec = require("../../utils/exec.js");
|
|
38
|
-
var import_logging = require("../../utils/logging.js");
|
|
39
|
-
var import_lint = require("../lint/index.js");
|
|
40
|
-
var import_upgrade = require("../lint/internalLints/upgrade/index.js");
|
|
41
35
|
const test = async () => {
|
|
42
36
|
const argv = process.argv.slice(2);
|
|
43
37
|
const nodeOptions = process.env.NODE_OPTIONS ?? "";
|
|
44
|
-
if ((0, import_env.isCiEnv)()) {
|
|
45
|
-
const logger = (0, import_logging.createLogger)({ debug: (0, import_args.hasDebugFlag)(argv) });
|
|
46
|
-
try {
|
|
47
|
-
const result = await (0, import_upgrade.upgradeSkuba)(
|
|
48
|
-
"format",
|
|
49
|
-
(0, import_logging.childLogger)(logger, { suffixes: [(0, import_util.styleText)("dim", "upgrade-skuba")] })
|
|
50
|
-
);
|
|
51
|
-
if (result.upgraded) {
|
|
52
|
-
await (0, import_lint.lint)(argv);
|
|
53
|
-
}
|
|
54
|
-
} catch (error) {
|
|
55
|
-
logger.warn("Failed to upgrade skuba before tests.");
|
|
56
|
-
logger.subtle((0, import_util.inspect)(error));
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
38
|
const execWithEnv = (0, import_exec.createExec)({
|
|
60
39
|
env: {
|
|
61
40
|
NODE_OPTIONS: !nodeOptions.includes("--experimental-vm-modules") ? `${nodeOptions} --experimental-vm-modules --no-warnings=ExperimentalWarning` : nodeOptions
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/cli/test/index.ts"],
|
|
4
|
-
"sourcesContent": ["import {
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,
|
|
4
|
+
"sourcesContent": ["import { createExec } from '../../utils/exec.js';\n\nexport const test = async () => {\n const argv = process.argv.slice(2);\n\n const nodeOptions = process.env.NODE_OPTIONS ?? '';\n\n const execWithEnv = createExec({\n env: {\n NODE_OPTIONS: !nodeOptions.includes('--experimental-vm-modules')\n ? `${nodeOptions} --experimental-vm-modules --no-warnings=ExperimentalWarning`\n : nodeOptions,\n },\n });\n\n // Run Jest in a child process with proper environment\n return execWithEnv(require.resolve('jest/bin/jest'), ...argv);\n};\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,kBAA2B;AAEpB,MAAM,OAAO,YAAY;AAC9B,QAAM,OAAO,QAAQ,KAAK,MAAM,CAAC;AAEjC,QAAM,cAAc,QAAQ,IAAI,gBAAgB;AAEhD,QAAM,kBAAc,wBAAW;AAAA,IAC7B,KAAK;AAAA,MACH,cAAc,CAAC,YAAY,SAAS,2BAA2B,IAC3D,GAAG,WAAW,iEACd;AAAA,IACN;AAAA,EACF,CAAC;AAGD,SAAO,YAAY,gBAAgB,eAAe,GAAG,GAAG,IAAI;AAC9D;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|