@powerlines/plugin-unenv 0.1.106 → 0.1.108

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/index.cjs CHANGED
@@ -1 +1,49 @@
1
- Object.defineProperty(exports,`__esModule`,{value:!0});let e=require(`unenv`);const t=(t={})=>({name:`unenv`,async config(){return{unenv:t}},configResolved(){this.unenv=(0,e.defineEnv)(this.config.unenv||{}),this.config.build.alias??={},Array.isArray(this.config.build.alias)?this.config.build.alias=Object.entries(this.unenv.env.alias).reduce((e,[t,n])=>(e.find(e=>e.find===t)||e.push({find:t,replacement:n}),e),this.config.build.alias):this.config.build.alias={...this.unenv.env.alias,...this.config.build.alias},this.config.build.external??=[],this.config.build.external.push(...this.unenv.env.external),this.config.build.inject??={},this.config.build.inject={...this.unenv.env.inject,...this.config.build.inject},this.config.build.polyfill??=[],this.config.build.polyfill.push(...this.unenv.env.polyfill)}});var n=t;exports.default=n,exports.plugin=t;
1
+ Object.defineProperty(exports, '__esModule', { value: true });
2
+ let unenv = require("unenv");
3
+
4
+ //#region src/index.ts
5
+ /**
6
+ * The unenv plugin for Powerlines.
7
+ *
8
+ * @see https://unjs.dev/packages/unenv
9
+ *
10
+ * @param options - The unenv plugin user configuration options.
11
+ * @returns A Powerlines plugin to transform source code to be platform agnostic using unenv.
12
+ */
13
+ const plugin = (options = {}) => {
14
+ return {
15
+ name: "unenv",
16
+ async config() {
17
+ return { unenv: options };
18
+ },
19
+ configResolved() {
20
+ this.unenv = (0, unenv.defineEnv)(this.config.unenv || {});
21
+ this.config.build.alias ??= {};
22
+ if (Array.isArray(this.config.build.alias)) this.config.build.alias = Object.entries(this.unenv.env.alias).reduce((aliases, [key, value]) => {
23
+ if (!aliases.find((alias) => alias.find === key)) aliases.push({
24
+ find: key,
25
+ replacement: value
26
+ });
27
+ return aliases;
28
+ }, this.config.build.alias);
29
+ else this.config.build.alias = {
30
+ ...this.unenv.env.alias,
31
+ ...this.config.build.alias
32
+ };
33
+ this.config.build.external ??= [];
34
+ this.config.build.external.push(...this.unenv.env.external);
35
+ this.config.build.inject ??= {};
36
+ this.config.build.inject = {
37
+ ...this.unenv.env.inject,
38
+ ...this.config.build.inject
39
+ };
40
+ this.config.build.polyfill ??= [];
41
+ this.config.build.polyfill.push(...this.unenv.env.polyfill);
42
+ }
43
+ };
44
+ };
45
+ var src_default = plugin;
46
+
47
+ //#endregion
48
+ exports.default = src_default;
49
+ exports.plugin = plugin;
package/dist/index.mjs CHANGED
@@ -1 +1,47 @@
1
- import{defineEnv as e}from"unenv";const t=(t={})=>({name:`unenv`,async config(){return{unenv:t}},configResolved(){this.unenv=e(this.config.unenv||{}),this.config.build.alias??={},Array.isArray(this.config.build.alias)?this.config.build.alias=Object.entries(this.unenv.env.alias).reduce((e,[t,n])=>(e.find(e=>e.find===t)||e.push({find:t,replacement:n}),e),this.config.build.alias):this.config.build.alias={...this.unenv.env.alias,...this.config.build.alias},this.config.build.external??=[],this.config.build.external.push(...this.unenv.env.external),this.config.build.inject??={},this.config.build.inject={...this.unenv.env.inject,...this.config.build.inject},this.config.build.polyfill??=[],this.config.build.polyfill.push(...this.unenv.env.polyfill)}});var n=t;export{n as default,t as plugin};
1
+ import { defineEnv } from "unenv";
2
+
3
+ //#region src/index.ts
4
+ /**
5
+ * The unenv plugin for Powerlines.
6
+ *
7
+ * @see https://unjs.dev/packages/unenv
8
+ *
9
+ * @param options - The unenv plugin user configuration options.
10
+ * @returns A Powerlines plugin to transform source code to be platform agnostic using unenv.
11
+ */
12
+ const plugin = (options = {}) => {
13
+ return {
14
+ name: "unenv",
15
+ async config() {
16
+ return { unenv: options };
17
+ },
18
+ configResolved() {
19
+ this.unenv = defineEnv(this.config.unenv || {});
20
+ this.config.build.alias ??= {};
21
+ if (Array.isArray(this.config.build.alias)) this.config.build.alias = Object.entries(this.unenv.env.alias).reduce((aliases, [key, value]) => {
22
+ if (!aliases.find((alias) => alias.find === key)) aliases.push({
23
+ find: key,
24
+ replacement: value
25
+ });
26
+ return aliases;
27
+ }, this.config.build.alias);
28
+ else this.config.build.alias = {
29
+ ...this.unenv.env.alias,
30
+ ...this.config.build.alias
31
+ };
32
+ this.config.build.external ??= [];
33
+ this.config.build.external.push(...this.unenv.env.external);
34
+ this.config.build.inject ??= {};
35
+ this.config.build.inject = {
36
+ ...this.unenv.env.inject,
37
+ ...this.config.build.inject
38
+ };
39
+ this.config.build.polyfill ??= [];
40
+ this.config.build.polyfill.push(...this.unenv.env.polyfill);
41
+ }
42
+ };
43
+ };
44
+ var src_default = plugin;
45
+
46
+ //#endregion
47
+ export { src_default as default, plugin };
@@ -78,10 +78,18 @@ interface ParseOptions extends ParserOptions {
78
78
  */
79
79
  allowReturnOutsideFunction?: boolean;
80
80
  }
81
+ interface EmitOptions extends WriteOptions {
82
+ /**
83
+ * If true, will emit the file using {@link UnpluginBuildContext.emitFile | the bundler's emit function}.
84
+ */
85
+ emitWithBundler?: boolean;
86
+ needsCodeReference?: Parameters<UnpluginBuildContext["emitFile"]>[0]["needsCodeReference"];
87
+ originalFileName?: Parameters<UnpluginBuildContext["emitFile"]>[0]["originalFileName"];
88
+ }
81
89
  /**
82
90
  * Options for emitting entry virtual files
83
91
  */
84
- type EmitEntryOptions = WriteOptions & Omit<ResolvedEntryTypeDefinition, "file">;
92
+ type EmitEntryOptions = EmitOptions & Omit<ResolvedEntryTypeDefinition, "file">;
85
93
  /**
86
94
  * The unresolved Powerlines context.
87
95
  *
@@ -292,6 +300,22 @@ interface UnresolvedContext<TResolvedConfig extends ResolvedConfig = ResolvedCon
292
300
  * The Powerlines builtin virtual files
293
301
  */
294
302
  getBuiltins: () => Promise<VirtualFile[]>;
303
+ /**
304
+ * Resolves a file and writes it to the VFS if it does not already exist
305
+ *
306
+ * @param code - The source code of the file
307
+ * @param path - The path to write the file to
308
+ * @param options - Additional options for writing the file
309
+ */
310
+ emit: (code: string, path: string, options?: EmitOptions) => Promise<void>;
311
+ /**
312
+ * Synchronously resolves a file and writes it to the VFS if it does not already exist
313
+ *
314
+ * @param code - The source code of the file
315
+ * @param path - The path to write the file to
316
+ * @param options - Additional options for writing the file
317
+ */
318
+ emitSync: (code: string, path: string, options?: EmitOptions) => void;
295
319
  /**
296
320
  * Resolves a builtin virtual file and writes it to the VFS if it does not already exist
297
321
  *
@@ -300,7 +324,7 @@ interface UnresolvedContext<TResolvedConfig extends ResolvedConfig = ResolvedCon
300
324
  * @param path - An optional path to write the builtin file to
301
325
  * @param options - Additional options for writing the builtin file
302
326
  */
303
- emitBuiltin: (code: string, id: string, path?: string, options?: WriteOptions) => Promise<void>;
327
+ emitBuiltin: (code: string, id: string, path?: string, options?: EmitOptions) => Promise<void>;
304
328
  /**
305
329
  * Synchronously resolves a builtin virtual file and writes it to the VFS if it does not already exist
306
330
  *
@@ -309,7 +333,7 @@ interface UnresolvedContext<TResolvedConfig extends ResolvedConfig = ResolvedCon
309
333
  * @param path - An optional path to write the builtin file to
310
334
  * @param options - Additional options for writing the builtin file
311
335
  */
312
- emitBuiltinSync: (code: string, id: string, path?: string, options?: WriteOptions) => void;
336
+ emitBuiltinSync: (code: string, id: string, path?: string, options?: EmitOptions) => void;
313
337
  /**
314
338
  * Resolves a entry virtual file and writes it to the VFS if it does not already exist
315
339
  *
@@ -78,10 +78,18 @@ interface ParseOptions extends ParserOptions {
78
78
  */
79
79
  allowReturnOutsideFunction?: boolean;
80
80
  }
81
+ interface EmitOptions extends WriteOptions {
82
+ /**
83
+ * If true, will emit the file using {@link UnpluginBuildContext.emitFile | the bundler's emit function}.
84
+ */
85
+ emitWithBundler?: boolean;
86
+ needsCodeReference?: Parameters<UnpluginBuildContext["emitFile"]>[0]["needsCodeReference"];
87
+ originalFileName?: Parameters<UnpluginBuildContext["emitFile"]>[0]["originalFileName"];
88
+ }
81
89
  /**
82
90
  * Options for emitting entry virtual files
83
91
  */
84
- type EmitEntryOptions = WriteOptions & Omit<ResolvedEntryTypeDefinition, "file">;
92
+ type EmitEntryOptions = EmitOptions & Omit<ResolvedEntryTypeDefinition, "file">;
85
93
  /**
86
94
  * The unresolved Powerlines context.
87
95
  *
@@ -292,6 +300,22 @@ interface UnresolvedContext<TResolvedConfig extends ResolvedConfig = ResolvedCon
292
300
  * The Powerlines builtin virtual files
293
301
  */
294
302
  getBuiltins: () => Promise<VirtualFile[]>;
303
+ /**
304
+ * Resolves a file and writes it to the VFS if it does not already exist
305
+ *
306
+ * @param code - The source code of the file
307
+ * @param path - The path to write the file to
308
+ * @param options - Additional options for writing the file
309
+ */
310
+ emit: (code: string, path: string, options?: EmitOptions) => Promise<void>;
311
+ /**
312
+ * Synchronously resolves a file and writes it to the VFS if it does not already exist
313
+ *
314
+ * @param code - The source code of the file
315
+ * @param path - The path to write the file to
316
+ * @param options - Additional options for writing the file
317
+ */
318
+ emitSync: (code: string, path: string, options?: EmitOptions) => void;
295
319
  /**
296
320
  * Resolves a builtin virtual file and writes it to the VFS if it does not already exist
297
321
  *
@@ -300,7 +324,7 @@ interface UnresolvedContext<TResolvedConfig extends ResolvedConfig = ResolvedCon
300
324
  * @param path - An optional path to write the builtin file to
301
325
  * @param options - Additional options for writing the builtin file
302
326
  */
303
- emitBuiltin: (code: string, id: string, path?: string, options?: WriteOptions) => Promise<void>;
327
+ emitBuiltin: (code: string, id: string, path?: string, options?: EmitOptions) => Promise<void>;
304
328
  /**
305
329
  * Synchronously resolves a builtin virtual file and writes it to the VFS if it does not already exist
306
330
  *
@@ -309,7 +333,7 @@ interface UnresolvedContext<TResolvedConfig extends ResolvedConfig = ResolvedCon
309
333
  * @param path - An optional path to write the builtin file to
310
334
  * @param options - Additional options for writing the builtin file
311
335
  */
312
- emitBuiltinSync: (code: string, id: string, path?: string, options?: WriteOptions) => void;
336
+ emitBuiltinSync: (code: string, id: string, path?: string, options?: EmitOptions) => void;
313
337
  /**
314
338
  * Resolves a entry virtual file and writes it to the VFS if it does not already exist
315
339
  *
@@ -1 +1 @@
1
- export{};
1
+ export { };
@@ -1 +1 @@
1
- export{};
1
+ export { };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@powerlines/plugin-unenv",
3
- "version": "0.1.106",
3
+ "version": "0.1.108",
4
4
  "type": "module",
5
5
  "description": "A Powerlines plugin to transform source code to be platform agnostic using unenv.",
6
6
  "repository": {
@@ -117,19 +117,19 @@
117
117
  "files": ["dist/**/*"],
118
118
  "keywords": ["unenv", "powerlines", "storm-software", "powerlines-plugin"],
119
119
  "dependencies": {
120
- "@stryke/path": "^0.24.0",
121
- "@stryke/fs": "^0.33.26",
122
- "@stryke/hash": "^0.12.32",
120
+ "@stryke/path": "^0.24.1",
121
+ "@stryke/fs": "^0.33.27",
122
+ "@stryke/hash": "^0.12.33",
123
123
  "unenv": "npm:unenv-nightly@2.0.0-rc.24",
124
124
  "defu": "^6.1.4",
125
- "powerlines": "^0.36.22",
125
+ "powerlines": "^0.36.24",
126
126
  "typescript": "^5.9.3",
127
127
  "vite": "8.0.0-beta.2"
128
128
  },
129
129
  "devDependencies": {
130
- "@powerlines/nx": "^0.11.48",
130
+ "@powerlines/nx": "^0.11.50",
131
131
  "@types/node": "^24.10.4"
132
132
  },
133
133
  "publishConfig": { "access": "public" },
134
- "gitHead": "f88fe8eb30f96536b83fc9af884972d48e31e63a"
134
+ "gitHead": "4b695d4b3476fd9dd79521f92258d52dab2b8d72"
135
135
  }