Skip to content

Commit 6601545

Browse files
AugustinMauroyavivkellerJakobJingleheimer
authored
feat(logger): expose utils to other recipes (#93)
Co-authored-by: Aviv Keller <[email protected]> Co-authored-by: Jacob Smith <[email protected]>
1 parent f086e8f commit 6601545

18 files changed

+122
-29
lines changed

.github/workflows/codemod_publish.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ on:
55
push:
66
paths:
77
- "recipes/**"
8-
- "codemods/**"
98
branches:
109
- main
1110

CONTRIBUTING.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ files).
88
* unit tests
99
* end-to-end test(s) for accepted use-cases
1010
* a `test` command in `package.json`; there may be sub-commands like `test:unit` & `test:e2e`, but there must be a parent that combines them.
11-
* Include `--import='../../build/snapshots.mts` to standardise the filename (`${original_base_name}.snap.cjs`) across recipes.
11+
* Include `--import='@nodejs/codemod-utils/snapshots` to standardise the filename (`${original_base_name}.snap.cjs`) across recipes.
1212
* Ensure `--test-coverage-include` and `--test-coverage-exclude` are set correctly for the recipe's workspace. The root repo handles setting coverage rules like minimum line coverage.
1313
* Code comments (js docs, etc)
1414
* Types (either via typescript or jsdoc)
@@ -20,3 +20,6 @@ New recipes are added under `./recipes` in their own folder, succinctly named fo
2020
## Before pushing a commit
2121

2222
A convenient superset of checks is available via `node --run pre-commit`, which automatically fixes formatting and linting issues (that are safe to fix), checks types, and runs tests. Changes resulting from this should be committed.
23+
24+
> [!WARNING]
25+
> Some integration tests modify fixtures because they run the entire codemod. Remember to use the `git restore` command to restore these files before pushing a commit.

package-lock.json

Lines changed: 30 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
"lint:fix": "biome lint --fix ./",
88
"lint": "biome lint ./",
99
"pre-commit": "node --run lint:fix; node --run type-check; node --run test",
10-
"test": "npm run test --workspaces -- --import='./test/snapshots.ts' --experimental-test-coverage --test-reporter=spec --test-reporter-destination=stdout",
10+
"test": "npm run test --workspaces",
1111
"type-check": "tsc"
1212
},
1313
"repository": {
@@ -31,6 +31,7 @@
3131
"typescript": "^5.8.3"
3232
},
3333
"workspaces": [
34-
"./recipes/*"
34+
"./recipes/*",
35+
"utils"
3536
]
3637
}

recipes/correct-ts-specifiers/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
},
1010
"scripts": {
1111
"start": "node --no-warnings --experimental-import-meta-resolve --experimental-strip-types ./src/workflow.ts",
12-
"test": "node --no-warnings --experimental-import-meta-resolve --experimental-test-module-mocks --experimental-test-snapshots --experimental-strip-types --import='../../test/snapshots.ts' --test --experimental-test-coverage --test-coverage-include='src/**/*' --test-coverage-exclude='**/*.test.ts' './**/*.test.ts'"
12+
"test": "node --no-warnings --experimental-import-meta-resolve --experimental-test-module-mocks --experimental-test-snapshots --experimental-strip-types --import='@nodejs/codemod-utils/snapshots' --test --experimental-test-coverage --test-coverage-include='src/**/*' --test-coverage-exclude='**/*.test.ts' './**/*.test.ts'"
1313
},
1414
"repository": {
1515
"type": "git",
@@ -35,6 +35,7 @@
3535
"@nodejs-loaders/alias": "^2.1.2"
3636
},
3737
"devDependencies": {
38+
"@nodejs/codemod-utils": "*",
3839
"@types/node": "^24.0.3"
3940
}
4041
}

recipes/correct-ts-specifiers/src/map-imports.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import { dExts } from './exts.ts';
66
import type { FSAbsolutePath } from './index.d.ts';
77

88

9-
type Logger = typeof import('./logger.ts').logger;
9+
type Logger = typeof import('@nodejs/codemod-utils/logger').logger;
1010
type MapImports = typeof import('./map-imports.ts').mapImports;
1111

1212
describe('Map Imports', { concurrency: true }, () => {
@@ -17,7 +17,7 @@ describe('Map Imports', { concurrency: true }, () => {
1717
before(async () => {
1818
const logger = mock.fn<Logger>();
1919
({ mock: mock__log } = logger);
20-
mock.module('./logger.ts', {
20+
mock.module('@nodejs/codemod-utils/logger', {
2121
namedExports: { logger },
2222
});
2323

recipes/correct-ts-specifiers/src/map-imports.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1+
import { logger } from '@nodejs/codemod-utils/logger';
12
import type { FSAbsolutePath, Specifier } from './index.d.ts';
23
import { fexists } from './fexists.ts';
3-
import { logger } from './logger.ts';
44
import { isDir } from './is-dir.ts';
55
import { isIgnorableSpecifier } from './is-ignorable-specifier.ts';
66
import { replaceJSExtWithTSExt } from './replace-js-ext-with-ts-ext.ts';

recipes/correct-ts-specifiers/src/replace-js-ext-with-ts-ext.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import type { FSAbsolutePath } from './index.d.ts';
88

99
type MockModuleContext = ReturnType<typeof mock.module>;
1010

11-
type Logger = typeof import('./logger.ts').logger;
11+
type Logger = typeof import('@nodejs/codemod-utils/logger').logger;
1212
type ReplaceJSExtWithTSExt = typeof import('./replace-js-ext-with-ts-ext.ts').replaceJSExtWithTSExt;
1313

1414
describe('Correcting ts file extensions', { concurrency: true }, () => {
@@ -23,7 +23,7 @@ describe('Correcting ts file extensions', { concurrency: true }, () => {
2323
before(async () => {
2424
const logger = mock.fn<Logger>();
2525
({ mock: mock__log } = logger);
26-
mock__logger = mock.module('./logger.ts', {
26+
mock__logger = mock.module('@nodejs/codemod-utils/logger', {
2727
namedExports: { logger },
2828
});
2929

recipes/correct-ts-specifiers/src/replace-js-ext-with-ts-ext.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
import { extname } from 'node:path';
22

3+
import { logger } from '@nodejs/codemod-utils/logger';
4+
35
import type { FSAbsolutePath, NodeModSpecifier, ResolvedSpecifier, Specifier } from './index.d.ts';
46
import { type DExt, type JSExt, type TSExt, extSets, suspectExts } from './exts.ts';
57
import { fexists } from './fexists.ts';
6-
import { logger } from './logger.ts';
8+
79
import { isDir } from './is-dir.ts';
810

911
/**

recipes/correct-ts-specifiers/src/workflow.test.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,7 @@ import { execPath } from 'node:process';
33
import { readFile } from 'node:fs/promises';
44
import { describe, it } from 'node:test';
55
import { fileURLToPath } from 'node:url';
6-
7-
import { spawnPromisified } from '../../../test/spawn-promisified.ts';
6+
import { spawnPromisified } from '@nodejs/codemod-utils/spawn-promisified';
87

98
describe('workflow', () => {
109
it('should update bad specifiers and ignore good ones', async (t) => {

0 commit comments

Comments
 (0)