Skip to content

Commit bf3be6a

Browse files
first review
1 parent 48e0b44 commit bf3be6a

File tree

10 files changed

+22
-22
lines changed

10 files changed

+22
-22
lines changed

package-lock.json

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
{
22
"$schema": "https://codemod-utils.s3.us-west-1.amazonaws.com/configuration_schema.json",
3-
"name": "@nodejs/import-attributes",
4-
"description": "Replace erroneous 'js' or omitted file extensions of import specifiers in TypeScript files.",
3+
"name": "@nodejs/import-assertions-to-attributes",
4+
"description": "",
55
"version": "1.0.0",
6-
"engine": "workflow",
6+
"engine": "ast-grep",
77
"private": false,
88
"entry": "./src/workflow.ts",
99
"arguments": [],
@@ -12,8 +12,7 @@
1212
"tags": [
1313
"esm",
1414
"import",
15-
"node",
16-
"typescript"
15+
"node"
1716
]
1817
}
1918
}

recipes/import-attributes/package.json renamed to recipes/import-assertions-to-attributes/package.json

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"name": "@nodejs/import-attributes",
2+
"name": "@nodejs/import-assertions-to-attributes",
33
"version": "1.0.0",
44
"description": "Replace `assert` import arrtibute to the `with` ECMAScript import attribute.",
55
"type": "module",
@@ -14,7 +14,7 @@
1414
"repository": {
1515
"type": "git",
1616
"url": "git+https://github.com/nodejs/userland-migrations.git",
17-
"directory": "recipes/import-attributes",
17+
"directory": "recipes/import-assertions-to-attributes",
1818
"bugs": "https://github.com/nodejs/userland-migrations/issues"
1919
},
2020
"files": [
@@ -24,12 +24,11 @@
2424
],
2525
"keywords": [
2626
"codemod",
27-
"esm",
28-
"typescript"
27+
"esm"
2928
],
30-
"author": "Jacob Smith",
29+
"author": "Augustin Mauroy",
3130
"license": "MIT",
32-
"homepage": "https://github.com/nodejs/userland-migrations/tree/main/import-attributes#readme",
31+
"homepage": "https://github.com/nodejs/userland-migrations/tree/main/import-assertions-to-attributes#readme",
3332
"devDependencies": {
3433
"@types/node": "^24.0.3"
3534
},

recipes/import-attributes/src/workflow.ts renamed to recipes/import-assertions-to-attributes/src/workflow.ts

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ async function processModule({ astGrep }: Helpers) {
1212
any: [
1313
// cover `import { something } from './module.json' assert { type: 'json' };`
1414
{ kind: 'import_statement', regex: "import\\s+.*\\s+assert\\s*\\{" },
15+
{ kind: 'import_statement', regex: "import\\s+.*\\s+with\\s*\\{" },
1516
// cover `import('./module.json', { assert: { type: 'json' } })`
1617
{
1718
kind: 'call_expression', pattern: "import($SPECIFIER, { assert: $ASSERT })",
@@ -25,10 +26,11 @@ async function processModule({ astGrep }: Helpers) {
2526

2627
if (kind === 'import_statement') {
2728
// Modify import statement with assert
28-
29+
const children = node.children();
30+
console.log(children.map(child => child.kind()));
2931
} else if (kind === 'call_expression') {
3032
// Modify dynamic import with assert
31-
const children = node.children();
33+
/*const children = node.children();
3234
3335
if (children.length > 2) {
3436
throw new Error(`Expected 2 children, got ${children.length}`);
@@ -57,8 +59,7 @@ async function processModule({ astGrep }: Helpers) {
5759
5860
// Replace "assert" with "with" and keep the same value
5961
const newTypePair = `with: ${assertValue.text()}`;
60-
edits.push(assertPair.replace(newTypePair));
61-
62+
edits.push(assertPair.replace(newTypePair));*/
6263
} else {
6364
throw new Error(`Unexpected node kind: ${node.kind}`);
6465
}
@@ -88,11 +89,11 @@ async function processModule({ astGrep }: Helpers) {
8889
*/
8990
export async function workflow({ files }: Api) {
9091
console.log(
91-
`${styleText(["bold", "blue"], "[import-attributes]")}: Modifying import attributes to use 'with' instead of 'assert'`,
92+
`${styleText(["bold", "blue"], "[import-assertions-to-attributes]")}: Modifying import attributes to use 'with' instead of 'assert'`,
9293
);
9394
await files(globPattern).jsFam(processModule);
9495
console.log(
95-
`${styleText(["bold", "blue"], "[import-attributes]")}: Finished modifying import attributes`,
96+
`${styleText(["bold", "blue"], "[import-assertions-to-attributes]")}: Finished modifying import attributes`,
9697
);
9798
};
9899

recipes/import-attributes/tests/fixtures/file-edge-case.js renamed to recipes/import-assertions-to-attributes/tests/fixtures/file-edge-case.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { createRequire } from 'node:module';
22
import data from './data.json' assert { type: 'json' };
3+
import cacaDeMerde from './caca-de-merde.js' with { type: 'json' };
34
const require = createRequire(import.meta.url);
45
const foo = require('./foo.js');
56

recipes/import-attributes/tests/workflow.test.ts renamed to recipes/import-assertions-to-attributes/tests/workflow.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import { spawnPromisified } from '../../../test/spawn-promisified.ts';
77

88
const fixturesDir = new URL("./fixtures", import.meta.url);
99

10-
describe("workflow - import-attributes", async () => {
10+
describe("workflow - import-assertions-to-attributes", async () => {
1111
await spawnPromisified(
1212
execPath,
1313
[

0 commit comments

Comments
 (0)