Skip to content

Commit aae27cc

Browse files
committed
feature: @putout/plugin-package-json: remove-exports-with-missing-files: node
1 parent bfcde8f commit aae27cc

File tree

6 files changed

+58
-2
lines changed

6 files changed

+58
-2
lines changed
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
__putout_processor_json({
2+
"exports": {
3+
".": {
4+
"node": {
5+
"require": "./lib/test.js",
6+
"import": "./lib/test.mjs"
7+
}
8+
}
9+
}
10+
});

packages/plugin-package-json/lib/remove-exports-with-missing-files/find-keys/index.js

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,20 @@ function processNested({push, keyPath, valuePath}) {
4848
const root = keyPath.node.value;
4949

5050
for (const property of valuePath.get('properties')) {
51-
const key = `${root}+${property.node.key.value}`;
52-
const {value} = property.node.value;
51+
const valuePath = property.get('value');
52+
const keyPath = property.get('key');
53+
54+
if (valuePath.isObjectExpression()) {
55+
processNested({
56+
push,
57+
keyPath,
58+
valuePath,
59+
});
60+
continue;
61+
}
62+
63+
const key = `${root}+${keyPath.node.value}`;
64+
const {value} = valuePath.node;
5365

5466
push({
5567
key,

packages/plugin-package-json/lib/remove-exports-with-missing-files/find-keys/index.spec.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,3 +31,8 @@ test('putout: package-json: remove-exports-with-missing-files: find-keys: report
3131
t.report('nested', '.+require -> ./lib/test.js');
3232
t.end();
3333
});
34+
35+
test('putout: package-json: remove-exports-with-missing-files: find-keys: report: node', (t) => {
36+
t.report('node', 'node+require -> ./lib/test.js');
37+
t.end();
38+
});
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
__putout_processor_filesystem([
2+
"/",
3+
["/package.json", "ewogICAgICAgICAiZXhwb3J0cyI6IHsKICAgICAgICAgICAgIi4iOiB7CiAgICAgICAgICAgICAgICAibm9kZSI6IHsKICAgICAgICAgICAgICAgICAgICAicmVxdWlyZSI6ICIuL2xpYi9zdXBlcnRhcGUuanMiLAogICAgICAgICAgICAgICAgICAgICJpbXBvcnQiOiAiLi9saWIvc3VwZXJ0YXBlLm1qcyIKICAgICAgICAgICAgICAgIH0sCiAgICAgICAgICAgICAgICAiZGVmYXVsdCI6ICIuL2xpYi9zdXBlcnRhcGUuanMiCiAgICAgICAgICAgIH0KICAgICAgICB9CiAgICB9"],
4+
"/lib/",
5+
"/lib/supertape.js",
6+
"/lib/supertape.mjs"
7+
]);
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
__putout_processor_filesystem([
2+
"/",
3+
["/package.json", `{
4+
"exports": {
5+
".": {
6+
"node": {
7+
"require": "./lib/supertape.js",
8+
"import": "./lib/supertape.mjs"
9+
},
10+
"default": "./lib/supertape.js"
11+
}
12+
}
13+
}`],
14+
"/lib/",
15+
"/lib/supertape.js",
16+
"/lib/supertape.mjs",
17+
]);

packages/plugin-package-json/lib/remove-exports-with-missing-files/index.spec.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,3 +21,8 @@ test('package-json: remove-exports-with-missing-files: no report', (t) => {
2121
t.noReport('no-exports');
2222
t.end();
2323
});
24+
25+
test('package-json: remove-exports-with-missing-files: no report: node', (t) => {
26+
t.noReport('node');
27+
t.end();
28+
});

0 commit comments

Comments
 (0)