@idlebox/itypes 1.0.0 → 1.0.3
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.
package/package.json
CHANGED
|
@@ -1,17 +1,22 @@
|
|
|
1
1
|
{
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
2
|
+
"name": "@idlebox/itypes",
|
|
3
|
+
"type": "commonjs",
|
|
4
|
+
"version": "1.0.3",
|
|
5
|
+
"description": "some global variables copied from @types/node or dom",
|
|
6
|
+
"keywords": [
|
|
7
|
+
"Typescript",
|
|
8
|
+
"console",
|
|
9
|
+
"type",
|
|
10
|
+
"typings"
|
|
11
|
+
],
|
|
12
|
+
"license": "MIT",
|
|
13
|
+
"typings": "./index.d.ts",
|
|
14
|
+
"dependencies": {
|
|
15
|
+
"tslib": "^2.4.0"
|
|
16
|
+
},
|
|
17
|
+
"scripts": {
|
|
18
|
+
"build": "",
|
|
19
|
+
"clean": "",
|
|
20
|
+
"watch": ""
|
|
21
|
+
}
|
|
22
|
+
}
|
|
File without changes
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
const { basename, resolve } = require('path');
|
|
2
|
+
const { remove } = require('./remove');
|
|
3
|
+
|
|
4
|
+
const pluginName = require(resolve(__dirname, '../package.json')).name;
|
|
5
|
+
const PLUGIN_NAME = basename(pluginName);
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
*
|
|
9
|
+
* @param {import("@rushstack/heft").HeftSession} heftSession
|
|
10
|
+
* @param {*} heftConfiguration
|
|
11
|
+
* @param {*} options
|
|
12
|
+
*/
|
|
13
|
+
function removeTypes(heftSession, heftConfiguration, options = {}) {
|
|
14
|
+
heftSession.hooks.build.tap(PLUGIN_NAME, (build) => {
|
|
15
|
+
build.hooks.postBuild.tap(PLUGIN_NAME, (postBuild) => {
|
|
16
|
+
postBuild.hooks.run.tapPromise(PLUGIN_NAME, async function codegen() {
|
|
17
|
+
remove(heftConfiguration.buildFolder);
|
|
18
|
+
});
|
|
19
|
+
});
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
module.exports.pluginName = pluginName;
|
|
24
|
+
module.exports.PLUGIN_NAME = PLUGIN_NAME;
|
|
25
|
+
module.exports.apply = removeTypes;
|
|
@@ -1,15 +1,2 @@
|
|
|
1
|
-
const {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
const targetDts = resolve(process.cwd(), './docs/package-public.d.ts');
|
|
5
|
-
console.log('[@idlebox/itypes] fixing file: %s', targetDts);
|
|
6
|
-
let data = readFileSync(targetDts, 'utf-8').trim();
|
|
7
|
-
|
|
8
|
-
if (data.startsWith('/// ') && data.includes('@idlebox/itypes')) {
|
|
9
|
-
data = data.slice(data.indexOf('\n'));
|
|
10
|
-
data = data.trim() + '\n';
|
|
11
|
-
console.log('[@idlebox/itypes] updated, write back');
|
|
12
|
-
writeFileSync(targetDts, data, 'utf-8');
|
|
13
|
-
} else {
|
|
14
|
-
console.log('[@idlebox/itypes] no need update');
|
|
15
|
-
}
|
|
1
|
+
const { remove } = require('./remove');
|
|
2
|
+
remove(process.cwd());
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
const { readFileSync, writeFileSync } = require('fs');
|
|
2
|
+
const { resolve } = require('path');
|
|
3
|
+
|
|
4
|
+
module.exports.remove = function (cwd) {
|
|
5
|
+
const pkgFile = resolve(cwd, 'package.json');
|
|
6
|
+
const pkg = require(pkgFile);
|
|
7
|
+
const typingFile = pkg.types || pkg.typings;
|
|
8
|
+
|
|
9
|
+
if (!typingFile) {
|
|
10
|
+
throw new Error('missing types field in ' + pkgFile);
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
const targetDts = resolve(cwd, typingFile);
|
|
14
|
+
console.log('[@idlebox/itypes] fixing file: %s', targetDts);
|
|
15
|
+
const data = readFileSync(targetDts, 'utf-8');
|
|
16
|
+
|
|
17
|
+
const mr = /^\/\/\/.+$/gm;
|
|
18
|
+
for (const [line] of data.matchAll(mr)) {
|
|
19
|
+
if (line.includes('@idlebox/itypes')) {
|
|
20
|
+
console.log('[@idlebox/itypes] updated, write back');
|
|
21
|
+
writeFileSync(targetDts, data.replace(line, '').trimStart(), 'utf-8');
|
|
22
|
+
|
|
23
|
+
return;
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
console.log('[@idlebox/itypes] no need update');
|
|
28
|
+
};
|
package/remove.js
CHANGED
|
@@ -1 +1,31 @@
|
|
|
1
|
-
|
|
1
|
+
let walked = new WeakSet();
|
|
2
|
+
const parent = findParent(require.main);
|
|
3
|
+
walked = undefined;
|
|
4
|
+
|
|
5
|
+
if (!parent) {
|
|
6
|
+
throw new Error('[@idlebox/itypes] Can not find who import this file.');
|
|
7
|
+
}
|
|
8
|
+
if (parent.id.includes('@rushstack/heft')) {
|
|
9
|
+
module.exports = require('./remove-script/heft.js');
|
|
10
|
+
} else if (parent.id.includes('@build-script/builder')) {
|
|
11
|
+
require('./remove-script/buildscript.js');
|
|
12
|
+
} else {
|
|
13
|
+
throw new Error('[@idlebox/itypes] Can not detect builder type.');
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
function findParent(parent) {
|
|
17
|
+
for (const child of parent.children) {
|
|
18
|
+
if (walked.has(child)) {
|
|
19
|
+
continue;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
if (child === module) {
|
|
23
|
+
return parent;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
walked.add(child);
|
|
27
|
+
|
|
28
|
+
const found = findParent(child);
|
|
29
|
+
if (found) return found;
|
|
30
|
+
}
|
|
31
|
+
}
|