@idlebox/itypes 1.0.19 → 1.0.21

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/lib.bare.d.ts ADDED
@@ -0,0 +1,9 @@
1
+ /**
2
+ * 本文件导出环境类型同时不是node也不是web时的全局声明
3
+ */
4
+
5
+ /// <reference path="./lib.es.d.ts" />
6
+
7
+ /// <reference path="./typings/console.d.ts" />
8
+ /// <reference path="./typings/url.d.ts" />
9
+ /// <reference path="./typings/v8-error.d.ts" />
package/lib.dom.d.ts ADDED
@@ -0,0 +1,8 @@
1
+ /**
2
+ * 本文件导出环境类型为dom时的全局声明
3
+ */
4
+
5
+ /// <reference lib="dom" />
6
+ /// <reference path="./lib.es.d.ts" />
7
+
8
+ /// <reference path="./typings/v8-error.d.ts" />
package/lib.es.d.ts ADDED
@@ -0,0 +1,6 @@
1
+ /**
2
+ * 对esnext的补充
3
+ */
4
+
5
+ /// <reference path="./typings/common/timeout.d.ts" />
6
+ /// <reference path="./typings/common/export-meta.d.ts" />
package/lib.node.d.ts ADDED
@@ -0,0 +1,6 @@
1
+ /**
2
+ * 本文件导出环境类型为dom时的全局声明
3
+ */
4
+
5
+ /// <reference types="node" />
6
+ /// <reference path="./lib.es.d.ts" />
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@idlebox/itypes",
3
3
  "type": "module",
4
- "version": "1.0.19",
4
+ "version": "1.0.21",
5
5
  "description": "some global variables copied from @types/node or dom",
6
6
  "keywords": [
7
7
  "Typescript",
@@ -10,10 +10,22 @@
10
10
  "typings"
11
11
  ],
12
12
  "devDependencies": {
13
- "@mpis/run": "^0.0.21",
13
+ "@mpis/run": "^0.0.27",
14
14
  "@build-script/baseline-rig": "latest"
15
15
  },
16
16
  "exports": {
17
+ ".": {
18
+ "types": "./lib.es.d.ts"
19
+ },
20
+ "./node": {
21
+ "types": "./lib.node.d.ts"
22
+ },
23
+ "./dom": {
24
+ "types": "./lib.dom.d.ts"
25
+ },
26
+ "./bare": {
27
+ "types": "./lib.bare.d.ts"
28
+ },
17
29
  "./package.json": "./package.json"
18
30
  },
19
31
  "sideEffects": false,
@@ -0,0 +1,19 @@
1
+ {
2
+ "name": "@idlebox/itypes-bare",
3
+ "type": "module",
4
+ "version": "0.0.3",
5
+ "description": "bare export of @idlebox/itypes",
6
+ "scripts": {
7
+ "build": "",
8
+ "watch": "",
9
+ "clean": ""
10
+ },
11
+ "devDependencies": {
12
+ "@idlebox/itypes": "workspace:latest"
13
+ },
14
+ "types": "./node_modules/@idlebox/itypes/lib.bare.d.ts",
15
+ "exports": {
16
+ "./package.json": "./package.json"
17
+ },
18
+ "sideEffects": false
19
+ }
@@ -0,0 +1,19 @@
1
+ {
2
+ "name": "@idlebox/itypes-dom",
3
+ "type": "module",
4
+ "version": "0.0.3",
5
+ "description": "dom export of @idlebox/itypes",
6
+ "scripts": {
7
+ "build": "",
8
+ "watch": "",
9
+ "clean": ""
10
+ },
11
+ "devDependencies": {
12
+ "@idlebox/itypes": "workspace:latest"
13
+ },
14
+ "types": "./node_modules/@idlebox/itypes/lib.dom.d.ts",
15
+ "exports": {
16
+ "./package.json": "./package.json"
17
+ },
18
+ "sideEffects": false
19
+ }
@@ -0,0 +1,19 @@
1
+ {
2
+ "name": "@idlebox/itypes-node",
3
+ "type": "module",
4
+ "version": "0.0.3",
5
+ "description": "node export of @idlebox/itypes",
6
+ "scripts": {
7
+ "build": "",
8
+ "watch": "",
9
+ "clean": ""
10
+ },
11
+ "devDependencies": {
12
+ "@idlebox/itypes": "workspace:latest"
13
+ },
14
+ "types": "./node_modules/@idlebox/itypes/lib.node.d.ts",
15
+ "exports": {
16
+ "./package.json": "./package.json"
17
+ },
18
+ "sideEffects": false
19
+ }
@@ -0,0 +1,8 @@
1
+ declare interface ImportMeta {
2
+ readonly env: ImportMetaEnv;
3
+ }
4
+
5
+ declare interface ImportMetaEnv extends Record<string, string | boolean | undefined> {
6
+ readonly PROD: boolean;
7
+ readonly DEV: boolean;
8
+ }
@@ -0,0 +1,8 @@
1
+ // @ts-ignore
2
+ type ITimeoutType = NodeJS.Timeout;
3
+
4
+ declare type ITimerHandler = string | Function;
5
+ declare function clearInterval(handle?: ITimeoutType): void;
6
+ declare function clearTimeout(handle?: ITimeoutType): void;
7
+ declare function setInterval(handler: ITimerHandler, timeout?: ITimeoutType, ...arguments: any[]): ITimeoutType;
8
+ declare function setTimeout(handler: ITimerHandler, timeout?: ITimeoutType, ...arguments: any[]): ITimeoutType;
@@ -1,3 +1,5 @@
1
+ // @ts-nocheck
2
+
1
3
  // This needs to be global to avoid TS2403 in case lib.dom.d.ts is present in the same build
2
4
  interface Console {
3
5
  /**
@@ -0,0 +1,9 @@
1
+ declare interface ErrorConstructor {
2
+ captureStackTrace(targetObject: Object, constructor?: Function): void;
3
+ stackTraceLimit: number;
4
+ }
5
+
6
+ // declare namespace NodeJS {
7
+ // type Signals = string;
8
+ // interface ErrnoException extends Error {}
9
+ // }
package/error.d.ts DELETED
@@ -1,9 +0,0 @@
1
- declare interface ErrorConstructor {
2
- captureStackTrace: any;
3
- stackTraceLimit: number;
4
- }
5
-
6
- declare namespace NodeJS {
7
- type Signals = string;
8
- interface ErrnoException extends Error {}
9
- }
package/filter-dts.js DELETED
@@ -1,35 +0,0 @@
1
- const { resolve } = require('node:path');
2
- const { readFileSync, writeFileSync } = require('node:fs');
3
-
4
- function action(file) {
5
- const data = readFileSync(file, 'utf-8');
6
-
7
- lines = data.split('\n').filter((l) => {
8
- return !l.includes('@idlebox/itypes');
9
- });
10
-
11
- const result = `${lines.join('\n').trim()}\n`;
12
-
13
- if (result !== data) {
14
- writeFileSync(file, result);
15
- return true;
16
- }
17
- return false;
18
- }
19
-
20
- const PLUGIN_NAME = 'filter-dts';
21
-
22
- module.exports = class CopyDtsIndexPlugin {
23
- apply(session, configuration) {
24
- session.hooks.run.tapPromise(PLUGIN_NAME, async (_opt) => {
25
- console.error('todo');
26
- const root = resolve(configuration.buildFolderPath, 'lib');
27
-
28
- const ch1 = action(resolve(root, 'esm/__create_index.generated.d.mts'));
29
- if (ch1) session.logger.terminal.writeLine('.d.mts filtered.');
30
-
31
- const ch2 = action(resolve(root, 'cjs/__create_index.generated.d.cts'));
32
- if (ch2) session.logger.terminal.writeLine('.d.mts filtered.');
33
- });
34
- }
35
- };
package/heft-plugin.json DELETED
@@ -1,9 +0,0 @@
1
- {
2
- "$schema": "https://developer.microsoft.com/json-schemas/heft/v0/heft-plugin.schema.json",
3
- "taskPlugins": [
4
- {
5
- "pluginName": "filter-dts",
6
- "entryPoint": "./filter-dts.js"
7
- }
8
- ]
9
- }
package/index.d.ts DELETED
@@ -1,4 +0,0 @@
1
- /// <reference path="./console.d.ts" />
2
- /// <reference path="./timeout.d.ts" />
3
- /// <reference path="./url.d.ts" />
4
- /// <reference path="./error.d.ts" />
@@ -1,6 +0,0 @@
1
- const { buildContext } = require('@build-script/builder');
2
- const { resolve } = require('node:path');
3
-
4
- buildContext.registerAlias('remove-extra-lib', resolve(__dirname, './postbuild.script.js'));
5
- buildContext.addAction('post-build', ['remove-extra-lib']);
6
- buildContext.postfixAction('build', ['post-build']);
@@ -1,5 +0,0 @@
1
- {
2
- "name": "script",
3
- "type": "commonjs",
4
- "private": true
5
- }
@@ -1,2 +0,0 @@
1
- const { remove } = require('./remove.js');
2
- remove(process.cwd());
@@ -1,28 +0,0 @@
1
- const { readFileSync, writeFileSync } = require('node:fs');
2
- const { resolve } = require('node:path');
3
-
4
- module.exports.remove = (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 DELETED
@@ -1,31 +0,0 @@
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
- }
package/timeout.d.ts DELETED
@@ -1,5 +0,0 @@
1
- declare type TimerHandler = string | Function;
2
- declare function clearInterval(handle?: number): void;
3
- declare function clearTimeout(handle?: number): void;
4
- declare function setInterval(handler: TimerHandler, timeout?: number, ...arguments: any[]): number;
5
- declare function setTimeout(handler: TimerHandler, timeout?: number, ...arguments: any[]): number;
File without changes