@powerlines/plugin-unimport 0.1.118 → 0.1.120
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/dist/_virtual/rolldown_runtime.cjs +29 -1
- package/dist/index.cjs +83 -1
- package/dist/index.mjs +79 -1
- package/dist/powerlines/src/types/context.d.cts +27 -3
- package/dist/powerlines/src/types/context.d.mts +27 -3
- package/dist/types/index.mjs +1 -1
- package/dist/types/plugin.mjs +1 -1
- package/package.json +11 -11
|
@@ -1 +1,29 @@
|
|
|
1
|
-
|
|
1
|
+
//#region rolldown:runtime
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __copyProps = (to, from, except, desc) => {
|
|
9
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
10
|
+
for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
|
|
11
|
+
key = keys[i];
|
|
12
|
+
if (!__hasOwnProp.call(to, key) && key !== except) {
|
|
13
|
+
__defProp(to, key, {
|
|
14
|
+
get: ((k) => from[k]).bind(null, key),
|
|
15
|
+
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
16
|
+
});
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
return to;
|
|
21
|
+
};
|
|
22
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
|
|
23
|
+
value: mod,
|
|
24
|
+
enumerable: true
|
|
25
|
+
}) : target, mod));
|
|
26
|
+
|
|
27
|
+
//#endregion
|
|
28
|
+
|
|
29
|
+
exports.__toESM = __toESM;
|
package/dist/index.cjs
CHANGED
|
@@ -1 +1,83 @@
|
|
|
1
|
-
Object.defineProperty(exports
|
|
1
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
2
|
+
const require_rolldown_runtime = require('./_virtual/rolldown_runtime.cjs');
|
|
3
|
+
let __storm_software_config_tools_types = require("@storm-software/config-tools/types");
|
|
4
|
+
let __stryke_helpers_throttle = require("@stryke/helpers/throttle");
|
|
5
|
+
let __stryke_json_storm_json = require("@stryke/json/storm-json");
|
|
6
|
+
let __stryke_path_join = require("@stryke/path/join");
|
|
7
|
+
let defu = require("defu");
|
|
8
|
+
defu = require_rolldown_runtime.__toESM(defu);
|
|
9
|
+
let unimport = require("unimport");
|
|
10
|
+
|
|
11
|
+
//#region src/index.ts
|
|
12
|
+
/**
|
|
13
|
+
* A Powerlines plugin to integrate Unimport for code generation.
|
|
14
|
+
*
|
|
15
|
+
* @param options - The plugin options.
|
|
16
|
+
* @returns A Powerlines plugin instance.
|
|
17
|
+
*/
|
|
18
|
+
const plugin = (options) => {
|
|
19
|
+
return {
|
|
20
|
+
name: "unimport",
|
|
21
|
+
config() {
|
|
22
|
+
return { unimport: (0, defu.default)(options, {
|
|
23
|
+
commentsDisable: [
|
|
24
|
+
"@unimport-disable",
|
|
25
|
+
"@unimport-ignore",
|
|
26
|
+
"@imports-disable",
|
|
27
|
+
"@imports-ignore",
|
|
28
|
+
"@powerlines-disable",
|
|
29
|
+
"@powerlines-ignore"
|
|
30
|
+
],
|
|
31
|
+
commentsDebug: [
|
|
32
|
+
"@unimport-debug",
|
|
33
|
+
"@imports-debug",
|
|
34
|
+
"@powerlines-debug"
|
|
35
|
+
],
|
|
36
|
+
injectAtEnd: true
|
|
37
|
+
}) };
|
|
38
|
+
},
|
|
39
|
+
async configResolved() {
|
|
40
|
+
const { injectImports, init, ...rest } = (0, unimport.createUnimport)(this.config.unimport);
|
|
41
|
+
this.unimport = { ...rest };
|
|
42
|
+
this.unimport.dumpImports = (0, __stryke_helpers_throttle.throttle)(async () => {
|
|
43
|
+
this.log(__storm_software_config_tools_types.LogLevelLabel.TRACE, "Dumping import file...");
|
|
44
|
+
const items = await this.unimport.getImports();
|
|
45
|
+
this.log(__storm_software_config_tools_types.LogLevelLabel.TRACE, `Writing imports-dump JSON file: ${(0, __stryke_path_join.joinPaths)(this.dataPath, "imports-dump.json")}`);
|
|
46
|
+
const content = __stryke_json_storm_json.StormJSON.stringify(items);
|
|
47
|
+
if (content.trim() !== this.unimport.lastImportsDump?.trim()) {
|
|
48
|
+
this.unimport.lastImportsDump = content;
|
|
49
|
+
await this.fs.write((0, __stryke_path_join.joinPaths)(this.dataPath, "imports-dump.json"), content);
|
|
50
|
+
}
|
|
51
|
+
}, 1e3);
|
|
52
|
+
this.unimport.injectImports = async (code, id, options$1) => {
|
|
53
|
+
const result = await injectImports(code, id, options$1);
|
|
54
|
+
if (!result.s.hasChanged()) return result;
|
|
55
|
+
await this.unimport.dumpImports();
|
|
56
|
+
return result;
|
|
57
|
+
};
|
|
58
|
+
this.unimport.init = async () => {
|
|
59
|
+
await init();
|
|
60
|
+
await this.unimport.dumpImports();
|
|
61
|
+
};
|
|
62
|
+
await this.unimport.init();
|
|
63
|
+
},
|
|
64
|
+
async transform(code, id) {
|
|
65
|
+
const result = await this.unimport.injectImports(code, id);
|
|
66
|
+
if (!result.s.hasChanged()) return null;
|
|
67
|
+
return {
|
|
68
|
+
id,
|
|
69
|
+
code: result.s.toString(),
|
|
70
|
+
map: result.s.generateMap({
|
|
71
|
+
source: id,
|
|
72
|
+
includeContent: true,
|
|
73
|
+
hires: true
|
|
74
|
+
})
|
|
75
|
+
};
|
|
76
|
+
}
|
|
77
|
+
};
|
|
78
|
+
};
|
|
79
|
+
var src_default = plugin;
|
|
80
|
+
|
|
81
|
+
//#endregion
|
|
82
|
+
exports.default = src_default;
|
|
83
|
+
exports.plugin = plugin;
|
package/dist/index.mjs
CHANGED
|
@@ -1 +1,79 @@
|
|
|
1
|
-
import{LogLevelLabel
|
|
1
|
+
import { LogLevelLabel } from "@storm-software/config-tools/types";
|
|
2
|
+
import { throttle } from "@stryke/helpers/throttle";
|
|
3
|
+
import { StormJSON } from "@stryke/json/storm-json";
|
|
4
|
+
import { joinPaths } from "@stryke/path/join";
|
|
5
|
+
import defu from "defu";
|
|
6
|
+
import { createUnimport } from "unimport";
|
|
7
|
+
|
|
8
|
+
//#region src/index.ts
|
|
9
|
+
/**
|
|
10
|
+
* A Powerlines plugin to integrate Unimport for code generation.
|
|
11
|
+
*
|
|
12
|
+
* @param options - The plugin options.
|
|
13
|
+
* @returns A Powerlines plugin instance.
|
|
14
|
+
*/
|
|
15
|
+
const plugin = (options) => {
|
|
16
|
+
return {
|
|
17
|
+
name: "unimport",
|
|
18
|
+
config() {
|
|
19
|
+
return { unimport: defu(options, {
|
|
20
|
+
commentsDisable: [
|
|
21
|
+
"@unimport-disable",
|
|
22
|
+
"@unimport-ignore",
|
|
23
|
+
"@imports-disable",
|
|
24
|
+
"@imports-ignore",
|
|
25
|
+
"@powerlines-disable",
|
|
26
|
+
"@powerlines-ignore"
|
|
27
|
+
],
|
|
28
|
+
commentsDebug: [
|
|
29
|
+
"@unimport-debug",
|
|
30
|
+
"@imports-debug",
|
|
31
|
+
"@powerlines-debug"
|
|
32
|
+
],
|
|
33
|
+
injectAtEnd: true
|
|
34
|
+
}) };
|
|
35
|
+
},
|
|
36
|
+
async configResolved() {
|
|
37
|
+
const { injectImports, init, ...rest } = createUnimport(this.config.unimport);
|
|
38
|
+
this.unimport = { ...rest };
|
|
39
|
+
this.unimport.dumpImports = throttle(async () => {
|
|
40
|
+
this.log(LogLevelLabel.TRACE, "Dumping import file...");
|
|
41
|
+
const items = await this.unimport.getImports();
|
|
42
|
+
this.log(LogLevelLabel.TRACE, `Writing imports-dump JSON file: ${joinPaths(this.dataPath, "imports-dump.json")}`);
|
|
43
|
+
const content = StormJSON.stringify(items);
|
|
44
|
+
if (content.trim() !== this.unimport.lastImportsDump?.trim()) {
|
|
45
|
+
this.unimport.lastImportsDump = content;
|
|
46
|
+
await this.fs.write(joinPaths(this.dataPath, "imports-dump.json"), content);
|
|
47
|
+
}
|
|
48
|
+
}, 1e3);
|
|
49
|
+
this.unimport.injectImports = async (code, id, options$1) => {
|
|
50
|
+
const result = await injectImports(code, id, options$1);
|
|
51
|
+
if (!result.s.hasChanged()) return result;
|
|
52
|
+
await this.unimport.dumpImports();
|
|
53
|
+
return result;
|
|
54
|
+
};
|
|
55
|
+
this.unimport.init = async () => {
|
|
56
|
+
await init();
|
|
57
|
+
await this.unimport.dumpImports();
|
|
58
|
+
};
|
|
59
|
+
await this.unimport.init();
|
|
60
|
+
},
|
|
61
|
+
async transform(code, id) {
|
|
62
|
+
const result = await this.unimport.injectImports(code, id);
|
|
63
|
+
if (!result.s.hasChanged()) return null;
|
|
64
|
+
return {
|
|
65
|
+
id,
|
|
66
|
+
code: result.s.toString(),
|
|
67
|
+
map: result.s.generateMap({
|
|
68
|
+
source: id,
|
|
69
|
+
includeContent: true,
|
|
70
|
+
hires: true
|
|
71
|
+
})
|
|
72
|
+
};
|
|
73
|
+
}
|
|
74
|
+
};
|
|
75
|
+
};
|
|
76
|
+
var src_default = plugin;
|
|
77
|
+
|
|
78
|
+
//#endregion
|
|
79
|
+
export { src_default as default, plugin };
|
|
@@ -79,10 +79,18 @@ interface ParseOptions extends ParserOptions {
|
|
|
79
79
|
*/
|
|
80
80
|
allowReturnOutsideFunction?: boolean;
|
|
81
81
|
}
|
|
82
|
+
interface EmitOptions extends WriteOptions {
|
|
83
|
+
/**
|
|
84
|
+
* If true, will emit the file using {@link UnpluginBuildContext.emitFile | the bundler's emit function}.
|
|
85
|
+
*/
|
|
86
|
+
emitWithBundler?: boolean;
|
|
87
|
+
needsCodeReference?: Parameters<UnpluginBuildContext["emitFile"]>[0]["needsCodeReference"];
|
|
88
|
+
originalFileName?: Parameters<UnpluginBuildContext["emitFile"]>[0]["originalFileName"];
|
|
89
|
+
}
|
|
82
90
|
/**
|
|
83
91
|
* Options for emitting entry virtual files
|
|
84
92
|
*/
|
|
85
|
-
type EmitEntryOptions =
|
|
93
|
+
type EmitEntryOptions = EmitOptions & Omit<ResolvedEntryTypeDefinition, "file">;
|
|
86
94
|
/**
|
|
87
95
|
* The unresolved Powerlines context.
|
|
88
96
|
*
|
|
@@ -293,6 +301,22 @@ interface UnresolvedContext<TResolvedConfig extends ResolvedConfig = ResolvedCon
|
|
|
293
301
|
* The Powerlines builtin virtual files
|
|
294
302
|
*/
|
|
295
303
|
getBuiltins: () => Promise<VirtualFile[]>;
|
|
304
|
+
/**
|
|
305
|
+
* Resolves a file and writes it to the VFS if it does not already exist
|
|
306
|
+
*
|
|
307
|
+
* @param code - The source code of the file
|
|
308
|
+
* @param path - The path to write the file to
|
|
309
|
+
* @param options - Additional options for writing the file
|
|
310
|
+
*/
|
|
311
|
+
emit: (code: string, path: string, options?: EmitOptions) => Promise<void>;
|
|
312
|
+
/**
|
|
313
|
+
* Synchronously resolves a file and writes it to the VFS if it does not already exist
|
|
314
|
+
*
|
|
315
|
+
* @param code - The source code of the file
|
|
316
|
+
* @param path - The path to write the file to
|
|
317
|
+
* @param options - Additional options for writing the file
|
|
318
|
+
*/
|
|
319
|
+
emitSync: (code: string, path: string, options?: EmitOptions) => void;
|
|
296
320
|
/**
|
|
297
321
|
* Resolves a builtin virtual file and writes it to the VFS if it does not already exist
|
|
298
322
|
*
|
|
@@ -301,7 +325,7 @@ interface UnresolvedContext<TResolvedConfig extends ResolvedConfig = ResolvedCon
|
|
|
301
325
|
* @param path - An optional path to write the builtin file to
|
|
302
326
|
* @param options - Additional options for writing the builtin file
|
|
303
327
|
*/
|
|
304
|
-
emitBuiltin: (code: string, id: string, path?: string, options?:
|
|
328
|
+
emitBuiltin: (code: string, id: string, path?: string, options?: EmitOptions) => Promise<void>;
|
|
305
329
|
/**
|
|
306
330
|
* Synchronously resolves a builtin virtual file and writes it to the VFS if it does not already exist
|
|
307
331
|
*
|
|
@@ -310,7 +334,7 @@ interface UnresolvedContext<TResolvedConfig extends ResolvedConfig = ResolvedCon
|
|
|
310
334
|
* @param path - An optional path to write the builtin file to
|
|
311
335
|
* @param options - Additional options for writing the builtin file
|
|
312
336
|
*/
|
|
313
|
-
emitBuiltinSync: (code: string, id: string, path?: string, options?:
|
|
337
|
+
emitBuiltinSync: (code: string, id: string, path?: string, options?: EmitOptions) => void;
|
|
314
338
|
/**
|
|
315
339
|
* Resolves a entry virtual file and writes it to the VFS if it does not already exist
|
|
316
340
|
*
|
|
@@ -81,10 +81,18 @@ interface ParseOptions extends ParserOptions {
|
|
|
81
81
|
*/
|
|
82
82
|
allowReturnOutsideFunction?: boolean;
|
|
83
83
|
}
|
|
84
|
+
interface EmitOptions extends WriteOptions {
|
|
85
|
+
/**
|
|
86
|
+
* If true, will emit the file using {@link UnpluginBuildContext.emitFile | the bundler's emit function}.
|
|
87
|
+
*/
|
|
88
|
+
emitWithBundler?: boolean;
|
|
89
|
+
needsCodeReference?: Parameters<UnpluginBuildContext["emitFile"]>[0]["needsCodeReference"];
|
|
90
|
+
originalFileName?: Parameters<UnpluginBuildContext["emitFile"]>[0]["originalFileName"];
|
|
91
|
+
}
|
|
84
92
|
/**
|
|
85
93
|
* Options for emitting entry virtual files
|
|
86
94
|
*/
|
|
87
|
-
type EmitEntryOptions =
|
|
95
|
+
type EmitEntryOptions = EmitOptions & Omit<ResolvedEntryTypeDefinition, "file">;
|
|
88
96
|
/**
|
|
89
97
|
* The unresolved Powerlines context.
|
|
90
98
|
*
|
|
@@ -295,6 +303,22 @@ interface UnresolvedContext<TResolvedConfig extends ResolvedConfig = ResolvedCon
|
|
|
295
303
|
* The Powerlines builtin virtual files
|
|
296
304
|
*/
|
|
297
305
|
getBuiltins: () => Promise<VirtualFile[]>;
|
|
306
|
+
/**
|
|
307
|
+
* Resolves a file and writes it to the VFS if it does not already exist
|
|
308
|
+
*
|
|
309
|
+
* @param code - The source code of the file
|
|
310
|
+
* @param path - The path to write the file to
|
|
311
|
+
* @param options - Additional options for writing the file
|
|
312
|
+
*/
|
|
313
|
+
emit: (code: string, path: string, options?: EmitOptions) => Promise<void>;
|
|
314
|
+
/**
|
|
315
|
+
* Synchronously resolves a file and writes it to the VFS if it does not already exist
|
|
316
|
+
*
|
|
317
|
+
* @param code - The source code of the file
|
|
318
|
+
* @param path - The path to write the file to
|
|
319
|
+
* @param options - Additional options for writing the file
|
|
320
|
+
*/
|
|
321
|
+
emitSync: (code: string, path: string, options?: EmitOptions) => void;
|
|
298
322
|
/**
|
|
299
323
|
* Resolves a builtin virtual file and writes it to the VFS if it does not already exist
|
|
300
324
|
*
|
|
@@ -303,7 +327,7 @@ interface UnresolvedContext<TResolvedConfig extends ResolvedConfig = ResolvedCon
|
|
|
303
327
|
* @param path - An optional path to write the builtin file to
|
|
304
328
|
* @param options - Additional options for writing the builtin file
|
|
305
329
|
*/
|
|
306
|
-
emitBuiltin: (code: string, id: string, path?: string, options?:
|
|
330
|
+
emitBuiltin: (code: string, id: string, path?: string, options?: EmitOptions) => Promise<void>;
|
|
307
331
|
/**
|
|
308
332
|
* Synchronously resolves a builtin virtual file and writes it to the VFS if it does not already exist
|
|
309
333
|
*
|
|
@@ -312,7 +336,7 @@ interface UnresolvedContext<TResolvedConfig extends ResolvedConfig = ResolvedCon
|
|
|
312
336
|
* @param path - An optional path to write the builtin file to
|
|
313
337
|
* @param options - Additional options for writing the builtin file
|
|
314
338
|
*/
|
|
315
|
-
emitBuiltinSync: (code: string, id: string, path?: string, options?:
|
|
339
|
+
emitBuiltinSync: (code: string, id: string, path?: string, options?: EmitOptions) => void;
|
|
316
340
|
/**
|
|
317
341
|
* Resolves a entry virtual file and writes it to the VFS if it does not already exist
|
|
318
342
|
*
|
package/dist/types/index.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export{};
|
|
1
|
+
export { };
|
package/dist/types/plugin.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export{};
|
|
1
|
+
export { };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@powerlines/plugin-unimport",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.120",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "A Powerlines plugin to add imports to source code automatically via unimport.",
|
|
6
6
|
"repository": {
|
|
@@ -117,23 +117,23 @@
|
|
|
117
117
|
"files": ["dist/**/*"],
|
|
118
118
|
"keywords": ["unimport", "powerlines", "storm-software", "powerlines-plugin"],
|
|
119
119
|
"dependencies": {
|
|
120
|
-
"@stryke/path": "^0.24.
|
|
121
|
-
"@stryke/helpers": "^0.9.
|
|
122
|
-
"@stryke/fs": "^0.33.
|
|
123
|
-
"@stryke/json": "^0.9.
|
|
124
|
-
"@stryke/type-checks": "^0.5.
|
|
125
|
-
"@stryke/types": "^0.10.
|
|
120
|
+
"@stryke/path": "^0.24.1",
|
|
121
|
+
"@stryke/helpers": "^0.9.32",
|
|
122
|
+
"@stryke/fs": "^0.33.27",
|
|
123
|
+
"@stryke/json": "^0.9.33",
|
|
124
|
+
"@stryke/type-checks": "^0.5.15",
|
|
125
|
+
"@stryke/types": "^0.10.29",
|
|
126
126
|
"defu": "^6.1.4",
|
|
127
127
|
"jiti": "^2.6.1",
|
|
128
128
|
"unimport": "^5.6.0",
|
|
129
|
-
"powerlines": "^0.36.
|
|
129
|
+
"powerlines": "^0.36.24",
|
|
130
130
|
"magic-string": "^0.30.21"
|
|
131
131
|
},
|
|
132
132
|
"devDependencies": {
|
|
133
|
-
"@powerlines/nx": "^0.11.
|
|
134
|
-
"@powerlines/plugin-plugin": "^0.12.
|
|
133
|
+
"@powerlines/nx": "^0.11.50",
|
|
134
|
+
"@powerlines/plugin-plugin": "^0.12.71",
|
|
135
135
|
"@types/node": "^24.10.4"
|
|
136
136
|
},
|
|
137
137
|
"publishConfig": { "access": "public" },
|
|
138
|
-
"gitHead": "
|
|
138
|
+
"gitHead": "4b695d4b3476fd9dd79521f92258d52dab2b8d72"
|
|
139
139
|
}
|