@powerlines/core 0.2.11 → 0.2.13

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.
@@ -3,6 +3,8 @@ let __stryke_type_checks_is_set_object = require("@stryke/type-checks/is-set-obj
3
3
  let __stryke_type_checks_is_set_string = require("@stryke/type-checks/is-set-string");
4
4
 
5
5
  //#region src/lib/unplugin/module-resolution.ts
6
+ const VIRTUAL_MODULE_PREFIX = "powerlines-virtual:";
7
+ const VIRTUAL_MODULE_PREFIX_REGEX = /^powerlines-virtual:/;
6
8
  /**
7
9
  * Creates the module resolution hook functions for a Powerlines unplugin plugin instance.
8
10
  *
@@ -13,13 +15,11 @@ let __stryke_type_checks_is_set_string = require("@stryke/type-checks/is-set-str
13
15
  * @see https://rollupjs.org/plugin-development/#load
14
16
  *
15
17
  * @param context - The plugin context.
18
+ * @param options - Options for creating the module resolution functions.
16
19
  * @returns The module resolution hooks (`resolveId` and `load`).
17
20
  */
18
21
  function createUnpluginModuleResolutionFunctions(context, options = {}) {
19
22
  const ctx = context;
20
- let prefix = "";
21
- if ((0, __stryke_type_checks_is_set_string.isSetString)(options.prefix)) prefix = options.prefix;
22
- else if (options.prefix !== false) prefix = "\0powerlines:";
23
23
  return {
24
24
  async resolveId(id, importer, opts = { isEntry: false }) {
25
25
  let result = await ctx.$$internal.callHook("resolveId", {
@@ -30,7 +30,7 @@ function createUnpluginModuleResolutionFunctions(context, options = {}) {
30
30
  if ((0, __stryke_type_checks_is_set_string.isSetString)(result)) return result;
31
31
  else if ((0, __stryke_type_checks_is_set_object.isSetObject)(result)) return {
32
32
  ...result,
33
- id: result.virtual ? `${prefix}${result.id}` : result.id
33
+ id: result.virtual && options.prefix !== false ? `${VIRTUAL_MODULE_PREFIX}${result.id}` : result.id
34
34
  };
35
35
  result = await ctx.$$internal.callHook("resolveId", {
36
36
  sequential: true,
@@ -40,7 +40,7 @@ function createUnpluginModuleResolutionFunctions(context, options = {}) {
40
40
  if ((0, __stryke_type_checks_is_set_string.isSetString)(result)) return result;
41
41
  else if ((0, __stryke_type_checks_is_set_object.isSetObject)(result)) return {
42
42
  ...result,
43
- id: result.virtual ? `${prefix}${result.id}` : result.id
43
+ id: result.virtual && options.prefix !== false ? `${VIRTUAL_MODULE_PREFIX}${result.id}` : result.id
44
44
  };
45
45
  result = await ctx.resolve(id, importer, {
46
46
  isFile: true,
@@ -48,7 +48,7 @@ function createUnpluginModuleResolutionFunctions(context, options = {}) {
48
48
  });
49
49
  if ((0, __stryke_type_checks_is_set_object.isSetObject)(result)) return {
50
50
  ...result,
51
- id: result.virtual ? `${prefix}${result.id}` : result.id
51
+ id: result.virtual && options.prefix !== false ? `${VIRTUAL_MODULE_PREFIX}${result.id}` : result.id
52
52
  };
53
53
  result = await ctx.$$internal.callHook("resolveId", {
54
54
  sequential: true,
@@ -58,14 +58,14 @@ function createUnpluginModuleResolutionFunctions(context, options = {}) {
58
58
  if ((0, __stryke_type_checks_is_set_string.isSetString)(result)) return result;
59
59
  else if ((0, __stryke_type_checks_is_set_object.isSetObject)(result)) return {
60
60
  ...result,
61
- id: result.virtual ? `${prefix}${result.id}` : result.id
61
+ id: result.virtual && options.prefix !== false ? `${VIRTUAL_MODULE_PREFIX}${result.id}` : result.id
62
62
  };
63
63
  return null;
64
64
  },
65
65
  load: {
66
- filter: prefix ? { id: { include: [/* @__PURE__ */ new RegExp(`^${prefix.replace(/[.*+?^${}()|[\]\\]/g, "\\$&")}`)] } } : void 0,
66
+ filter: options.prefix !== false ? { id: { include: [VIRTUAL_MODULE_PREFIX_REGEX] } } : void 0,
67
67
  async handler(id) {
68
- const moduleId = prefix ? id.replace(new RegExp(`^${prefix.replace(/[.*+?^${}()|[\]\\]/g, "\\$&")}`, "g"), "") : id;
68
+ const moduleId = options.prefix !== false ? id.replace(VIRTUAL_MODULE_PREFIX, "") : id;
69
69
  let result = await ctx.$$internal.callHook("load", {
70
70
  sequential: true,
71
71
  result: "first",
@@ -4,14 +4,15 @@ import { UnpluginOptions } from "unplugin";
4
4
  //#region src/lib/unplugin/module-resolution.d.ts
5
5
  interface CreateUnpluginModuleResolutionFunctionsOptions {
6
6
  /**
7
- * A prefix to apply to all resolved module IDs. This can be used to create virtual modules by prefixing them with a specific string (e.g., `\0`).
7
+ * An indicator of whether to prefix virtual module IDs with a specific string. This is useful for ensuring that virtual modules are only processed by the plugin and not by other plugins or the bundler itself.
8
8
  *
9
9
  * @remarks
10
- * If set to `false`, no prefix will be applied, and resolved module IDs will be returned as-is. By default, this is set to `\0powerlines:`, which is a common convention for virtual modules in Rollup and Vite plugins.
10
+ * - If set to `true`, virtual module IDs will be prefixed with the string `powerlines-virtual:`.
11
+ * - If set to `false`, no prefix will be added to virtual module IDs.
11
12
  *
12
- * @defaultValue "\\0powerlines:"
13
+ * @defaultValue true
13
14
  */
14
- prefix?: string | boolean;
15
+ prefix?: boolean;
15
16
  }
16
17
  /**
17
18
  * Creates the module resolution hook functions for a Powerlines unplugin plugin instance.
@@ -23,6 +24,7 @@ interface CreateUnpluginModuleResolutionFunctionsOptions {
23
24
  * @see https://rollupjs.org/plugin-development/#load
24
25
  *
25
26
  * @param context - The plugin context.
27
+ * @param options - Options for creating the module resolution functions.
26
28
  * @returns The module resolution hooks (`resolveId` and `load`).
27
29
  */
28
30
  declare function createUnpluginModuleResolutionFunctions<TContext extends PluginContext = PluginContext>(context: TContext, options?: CreateUnpluginModuleResolutionFunctionsOptions): Pick<UnpluginOptions, "resolveId" | "load">;
@@ -1 +1 @@
1
- {"version":3,"file":"module-resolution.d.cts","names":[],"sources":["../../../src/lib/unplugin/module-resolution.ts"],"sourcesContent":[],"mappings":";;;;UA6BiB,8CAAA;;AAAjB;AAwBA;;;;;;EAKG,MAAA,CAAA,EAAA,MAAA,GAAA,OAAA;;;;;;;;;;;;;;iBALa,yDACG,gBAAgB,wBAExB,oBACA,iDACR,KAAK"}
1
+ {"version":3,"file":"module-resolution.d.cts","names":[],"sources":["../../../src/lib/unplugin/module-resolution.ts"],"sourcesContent":[],"mappings":";;;;UA6BiB,8CAAA;;AAAjB;AA6BA;;;;;;;EAKO,MAAA,CAAA,EAAA,OAAA;;;;;;;;;;;;;;;iBALS,yDACG,gBAAgB,wBAExB,oBACA,iDACR,KAAK"}
@@ -4,14 +4,15 @@ import { UnpluginOptions } from "unplugin";
4
4
  //#region src/lib/unplugin/module-resolution.d.ts
5
5
  interface CreateUnpluginModuleResolutionFunctionsOptions {
6
6
  /**
7
- * A prefix to apply to all resolved module IDs. This can be used to create virtual modules by prefixing them with a specific string (e.g., `\0`).
7
+ * An indicator of whether to prefix virtual module IDs with a specific string. This is useful for ensuring that virtual modules are only processed by the plugin and not by other plugins or the bundler itself.
8
8
  *
9
9
  * @remarks
10
- * If set to `false`, no prefix will be applied, and resolved module IDs will be returned as-is. By default, this is set to `\0powerlines:`, which is a common convention for virtual modules in Rollup and Vite plugins.
10
+ * - If set to `true`, virtual module IDs will be prefixed with the string `powerlines-virtual:`.
11
+ * - If set to `false`, no prefix will be added to virtual module IDs.
11
12
  *
12
- * @defaultValue "\\0powerlines:"
13
+ * @defaultValue true
13
14
  */
14
- prefix?: string | boolean;
15
+ prefix?: boolean;
15
16
  }
16
17
  /**
17
18
  * Creates the module resolution hook functions for a Powerlines unplugin plugin instance.
@@ -23,6 +24,7 @@ interface CreateUnpluginModuleResolutionFunctionsOptions {
23
24
  * @see https://rollupjs.org/plugin-development/#load
24
25
  *
25
26
  * @param context - The plugin context.
27
+ * @param options - Options for creating the module resolution functions.
26
28
  * @returns The module resolution hooks (`resolveId` and `load`).
27
29
  */
28
30
  declare function createUnpluginModuleResolutionFunctions<TContext extends PluginContext = PluginContext>(context: TContext, options?: CreateUnpluginModuleResolutionFunctionsOptions): Pick<UnpluginOptions, "resolveId" | "load">;
@@ -1 +1 @@
1
- {"version":3,"file":"module-resolution.d.mts","names":[],"sources":["../../../src/lib/unplugin/module-resolution.ts"],"sourcesContent":[],"mappings":";;;;UA6BiB,8CAAA;;AAAjB;AAwBA;;;;;;EAKG,MAAA,CAAA,EAAA,MAAA,GAAA,OAAA;;;;;;;;;;;;;;iBALa,yDACG,gBAAgB,wBAExB,oBACA,iDACR,KAAK"}
1
+ {"version":3,"file":"module-resolution.d.mts","names":[],"sources":["../../../src/lib/unplugin/module-resolution.ts"],"sourcesContent":[],"mappings":";;;;UA6BiB,8CAAA;;AAAjB;AA6BA;;;;;;;EAKO,MAAA,CAAA,EAAA,OAAA;;;;;;;;;;;;;;;iBALS,yDACG,gBAAgB,wBAExB,oBACA,iDACR,KAAK"}
@@ -2,6 +2,8 @@ import { isSetObject } from "@stryke/type-checks/is-set-object";
2
2
  import { isSetString } from "@stryke/type-checks/is-set-string";
3
3
 
4
4
  //#region src/lib/unplugin/module-resolution.ts
5
+ const VIRTUAL_MODULE_PREFIX = "powerlines-virtual:";
6
+ const VIRTUAL_MODULE_PREFIX_REGEX = /^powerlines-virtual:/;
5
7
  /**
6
8
  * Creates the module resolution hook functions for a Powerlines unplugin plugin instance.
7
9
  *
@@ -12,13 +14,11 @@ import { isSetString } from "@stryke/type-checks/is-set-string";
12
14
  * @see https://rollupjs.org/plugin-development/#load
13
15
  *
14
16
  * @param context - The plugin context.
17
+ * @param options - Options for creating the module resolution functions.
15
18
  * @returns The module resolution hooks (`resolveId` and `load`).
16
19
  */
17
20
  function createUnpluginModuleResolutionFunctions(context, options = {}) {
18
21
  const ctx = context;
19
- let prefix = "";
20
- if (isSetString(options.prefix)) prefix = options.prefix;
21
- else if (options.prefix !== false) prefix = "\0powerlines:";
22
22
  return {
23
23
  async resolveId(id, importer, opts = { isEntry: false }) {
24
24
  let result = await ctx.$$internal.callHook("resolveId", {
@@ -29,7 +29,7 @@ function createUnpluginModuleResolutionFunctions(context, options = {}) {
29
29
  if (isSetString(result)) return result;
30
30
  else if (isSetObject(result)) return {
31
31
  ...result,
32
- id: result.virtual ? `${prefix}${result.id}` : result.id
32
+ id: result.virtual && options.prefix !== false ? `${VIRTUAL_MODULE_PREFIX}${result.id}` : result.id
33
33
  };
34
34
  result = await ctx.$$internal.callHook("resolveId", {
35
35
  sequential: true,
@@ -39,7 +39,7 @@ function createUnpluginModuleResolutionFunctions(context, options = {}) {
39
39
  if (isSetString(result)) return result;
40
40
  else if (isSetObject(result)) return {
41
41
  ...result,
42
- id: result.virtual ? `${prefix}${result.id}` : result.id
42
+ id: result.virtual && options.prefix !== false ? `${VIRTUAL_MODULE_PREFIX}${result.id}` : result.id
43
43
  };
44
44
  result = await ctx.resolve(id, importer, {
45
45
  isFile: true,
@@ -47,7 +47,7 @@ function createUnpluginModuleResolutionFunctions(context, options = {}) {
47
47
  });
48
48
  if (isSetObject(result)) return {
49
49
  ...result,
50
- id: result.virtual ? `${prefix}${result.id}` : result.id
50
+ id: result.virtual && options.prefix !== false ? `${VIRTUAL_MODULE_PREFIX}${result.id}` : result.id
51
51
  };
52
52
  result = await ctx.$$internal.callHook("resolveId", {
53
53
  sequential: true,
@@ -57,14 +57,14 @@ function createUnpluginModuleResolutionFunctions(context, options = {}) {
57
57
  if (isSetString(result)) return result;
58
58
  else if (isSetObject(result)) return {
59
59
  ...result,
60
- id: result.virtual ? `${prefix}${result.id}` : result.id
60
+ id: result.virtual && options.prefix !== false ? `${VIRTUAL_MODULE_PREFIX}${result.id}` : result.id
61
61
  };
62
62
  return null;
63
63
  },
64
64
  load: {
65
- filter: prefix ? { id: { include: [/* @__PURE__ */ new RegExp(`^${prefix.replace(/[.*+?^${}()|[\]\\]/g, "\\$&")}`)] } } : void 0,
65
+ filter: options.prefix !== false ? { id: { include: [VIRTUAL_MODULE_PREFIX_REGEX] } } : void 0,
66
66
  async handler(id) {
67
- const moduleId = prefix ? id.replace(new RegExp(`^${prefix.replace(/[.*+?^${}()|[\]\\]/g, "\\$&")}`, "g"), "") : id;
67
+ const moduleId = options.prefix !== false ? id.replace(VIRTUAL_MODULE_PREFIX, "") : id;
68
68
  let result = await ctx.$$internal.callHook("load", {
69
69
  sequential: true,
70
70
  result: "first",
@@ -1 +1 @@
1
- {"version":3,"file":"module-resolution.mjs","names":[],"sources":["../../../src/lib/unplugin/module-resolution.ts"],"sourcesContent":["/* -------------------------------------------------------------------\n\n ⚡ Storm Software - Powerlines\n\n This code was released as part of the Powerlines project. Powerlines\n is maintained by Storm Software under the Apache-2.0 license, and is\n free for commercial and private use. For more information, please visit\n our licensing page at https://stormsoftware.com/licenses/projects/powerlines.\n\n Website: https://stormsoftware.com\n Repository: https://github.com/storm-software/powerlines\n Documentation: https://docs.stormsoftware.com/projects/powerlines\n Contact: https://stormsoftware.com/contact\n\n SPDX-License-Identifier: Apache-2.0\n\n ------------------------------------------------------------------- */\n\nimport { isSetObject } from \"@stryke/type-checks/is-set-object\";\nimport { isSetString } from \"@stryke/type-checks/is-set-string\";\nimport { LoadResult } from \"rollup\";\nimport type {\n UnpluginBuildContext,\n UnpluginContext,\n UnpluginOptions\n} from \"unplugin\";\nimport { UNSAFE_PluginContext } from \"../../types/_internal\";\nimport { PluginContext, ResolveResult } from \"../../types/context\";\n\nexport interface CreateUnpluginModuleResolutionFunctionsOptions {\n /**\n * A prefix to apply to all resolved module IDs. This can be used to create virtual modules by prefixing them with a specific string (e.g., `\\0`).\n *\n * @remarks\n * If set to `false`, no prefix will be applied, and resolved module IDs will be returned as-is. By default, this is set to `\\0powerlines:`, which is a common convention for virtual modules in Rollup and Vite plugins.\n *\n * @defaultValue \"\\\\0powerlines:\"\n */\n prefix?: string | boolean;\n}\n\n/**\n * Creates the module resolution hook functions for a Powerlines unplugin plugin instance.\n *\n * @remarks\n * This includes the `resolveId` and `load` hooks.\n *\n * @see https://rollupjs.org/plugin-development/#resolveid\n * @see https://rollupjs.org/plugin-development/#load\n *\n * @param context - The plugin context.\n * @returns The module resolution hooks (`resolveId` and `load`).\n */\nexport function createUnpluginModuleResolutionFunctions<\n TContext extends PluginContext = PluginContext\n>(\n context: TContext,\n options: CreateUnpluginModuleResolutionFunctionsOptions = {}\n): Pick<UnpluginOptions, \"resolveId\" | \"load\"> {\n const ctx = context as unknown as UNSAFE_PluginContext;\n\n let prefix = \"\";\n if (isSetString(options.prefix)) {\n prefix = options.prefix;\n } else if (options.prefix !== false) {\n prefix = \"\\0powerlines:\";\n }\n\n return {\n async resolveId(\n this: UnpluginBuildContext & UnpluginContext,\n id: string,\n importer?: string,\n opts: {\n isEntry: boolean;\n } = { isEntry: false }\n ): Promise<string | ResolveResult | null | undefined> {\n let result = await ctx.$$internal.callHook(\n \"resolveId\",\n {\n sequential: true,\n result: \"first\",\n order: \"pre\"\n },\n id,\n importer,\n opts\n );\n if (isSetString(result)) {\n return result;\n } else if (isSetObject(result)) {\n return {\n ...result,\n id: result.virtual ? `${prefix}${result.id}` : result.id\n };\n }\n\n result = await ctx.$$internal.callHook(\n \"resolveId\",\n {\n sequential: true,\n result: \"first\",\n order: \"normal\"\n },\n id,\n importer,\n opts\n );\n if (isSetString(result)) {\n return result;\n } else if (isSetObject(result)) {\n return {\n ...result,\n id: result.virtual ? `${prefix}${result.id}` : result.id\n };\n }\n\n result = await ctx.resolve(id, importer, { isFile: true, ...opts });\n if (isSetObject(result)) {\n return {\n ...result,\n id: result.virtual ? `${prefix}${result.id}` : result.id\n };\n }\n\n result = await ctx.$$internal.callHook(\n \"resolveId\",\n {\n sequential: true,\n result: \"first\",\n order: \"post\"\n },\n id,\n importer,\n opts\n );\n if (isSetString(result)) {\n return result;\n } else if (isSetObject(result)) {\n return {\n ...result,\n id: result.virtual ? `${prefix}${result.id}` : result.id\n };\n }\n\n return null;\n },\n load: {\n filter: prefix\n ? {\n id: {\n include: [\n new RegExp(`^${prefix.replace(/[.*+?^${}()|[\\]\\\\]/g, \"\\\\$&\")}`)\n ]\n }\n }\n : undefined,\n async handler(\n this: UnpluginBuildContext & UnpluginContext,\n id: string\n ): Promise<LoadResult | null | undefined> {\n const moduleId = prefix\n ? id.replace(\n new RegExp(\n `^${prefix.replace(/[.*+?^${}()|[\\]\\\\]/g, \"\\\\$&\")}`,\n \"g\"\n ),\n \"\"\n )\n : id;\n\n let result = await ctx.$$internal.callHook(\n \"load\",\n {\n sequential: true,\n result: \"first\",\n order: \"pre\"\n },\n moduleId\n );\n if (result) {\n return result;\n }\n\n result = await ctx.$$internal.callHook(\n \"load\",\n {\n sequential: true,\n result: \"first\",\n order: \"normal\"\n },\n moduleId\n );\n if (result) {\n return result;\n }\n\n result = await ctx.load(moduleId);\n if (result) {\n return result;\n }\n\n return ctx.$$internal.callHook(\n \"load\",\n {\n sequential: true,\n result: \"first\",\n order: \"post\"\n },\n moduleId\n );\n }\n }\n };\n}\n"],"mappings":";;;;;;;;;;;;;;;;AAqDA,SAAgB,wCAGd,SACA,UAA0D,EAAE,EACf;CAC7C,MAAM,MAAM;CAEZ,IAAI,SAAS;AACb,KAAI,YAAY,QAAQ,OAAO,CAC7B,UAAS,QAAQ;UACR,QAAQ,WAAW,MAC5B,UAAS;AAGX,QAAO;EACL,MAAM,UAEJ,IACA,UACA,OAEI,EAAE,SAAS,OAAO,EAC8B;GACpD,IAAI,SAAS,MAAM,IAAI,WAAW,SAChC,aACA;IACE,YAAY;IACZ,QAAQ;IACR,OAAO;IACR,EACD,IACA,UACA,KACD;AACD,OAAI,YAAY,OAAO,CACrB,QAAO;YACE,YAAY,OAAO,CAC5B,QAAO;IACL,GAAG;IACH,IAAI,OAAO,UAAU,GAAG,SAAS,OAAO,OAAO,OAAO;IACvD;AAGH,YAAS,MAAM,IAAI,WAAW,SAC5B,aACA;IACE,YAAY;IACZ,QAAQ;IACR,OAAO;IACR,EACD,IACA,UACA,KACD;AACD,OAAI,YAAY,OAAO,CACrB,QAAO;YACE,YAAY,OAAO,CAC5B,QAAO;IACL,GAAG;IACH,IAAI,OAAO,UAAU,GAAG,SAAS,OAAO,OAAO,OAAO;IACvD;AAGH,YAAS,MAAM,IAAI,QAAQ,IAAI,UAAU;IAAE,QAAQ;IAAM,GAAG;IAAM,CAAC;AACnE,OAAI,YAAY,OAAO,CACrB,QAAO;IACL,GAAG;IACH,IAAI,OAAO,UAAU,GAAG,SAAS,OAAO,OAAO,OAAO;IACvD;AAGH,YAAS,MAAM,IAAI,WAAW,SAC5B,aACA;IACE,YAAY;IACZ,QAAQ;IACR,OAAO;IACR,EACD,IACA,UACA,KACD;AACD,OAAI,YAAY,OAAO,CACrB,QAAO;YACE,YAAY,OAAO,CAC5B,QAAO;IACL,GAAG;IACH,IAAI,OAAO,UAAU,GAAG,SAAS,OAAO,OAAO,OAAO;IACvD;AAGH,UAAO;;EAET,MAAM;GACJ,QAAQ,SACJ,EACE,IAAI,EACF,SAAS,iBACP,IAAI,OAAO,IAAI,OAAO,QAAQ,uBAAuB,OAAO,GAAG,CAChE,EACF,EACF,GACD;GACJ,MAAM,QAEJ,IACwC;IACxC,MAAM,WAAW,SACb,GAAG,QACD,IAAI,OACF,IAAI,OAAO,QAAQ,uBAAuB,OAAO,IACjD,IACD,EACD,GACD,GACD;IAEJ,IAAI,SAAS,MAAM,IAAI,WAAW,SAChC,QACA;KACE,YAAY;KACZ,QAAQ;KACR,OAAO;KACR,EACD,SACD;AACD,QAAI,OACF,QAAO;AAGT,aAAS,MAAM,IAAI,WAAW,SAC5B,QACA;KACE,YAAY;KACZ,QAAQ;KACR,OAAO;KACR,EACD,SACD;AACD,QAAI,OACF,QAAO;AAGT,aAAS,MAAM,IAAI,KAAK,SAAS;AACjC,QAAI,OACF,QAAO;AAGT,WAAO,IAAI,WAAW,SACpB,QACA;KACE,YAAY;KACZ,QAAQ;KACR,OAAO;KACR,EACD,SACD;;GAEJ;EACF"}
1
+ {"version":3,"file":"module-resolution.mjs","names":[],"sources":["../../../src/lib/unplugin/module-resolution.ts"],"sourcesContent":["/* -------------------------------------------------------------------\n\n ⚡ Storm Software - Powerlines\n\n This code was released as part of the Powerlines project. Powerlines\n is maintained by Storm Software under the Apache-2.0 license, and is\n free for commercial and private use. For more information, please visit\n our licensing page at https://stormsoftware.com/licenses/projects/powerlines.\n\n Website: https://stormsoftware.com\n Repository: https://github.com/storm-software/powerlines\n Documentation: https://docs.stormsoftware.com/projects/powerlines\n Contact: https://stormsoftware.com/contact\n\n SPDX-License-Identifier: Apache-2.0\n\n ------------------------------------------------------------------- */\n\nimport { isSetObject } from \"@stryke/type-checks/is-set-object\";\nimport { isSetString } from \"@stryke/type-checks/is-set-string\";\nimport { LoadResult } from \"rollup\";\nimport type {\n UnpluginBuildContext,\n UnpluginContext,\n UnpluginOptions\n} from \"unplugin\";\nimport { UNSAFE_PluginContext } from \"../../types/_internal\";\nimport { PluginContext, ResolveResult } from \"../../types/context\";\n\nexport interface CreateUnpluginModuleResolutionFunctionsOptions {\n /**\n * An indicator of whether to prefix virtual module IDs with a specific string. This is useful for ensuring that virtual modules are only processed by the plugin and not by other plugins or the bundler itself.\n *\n * @remarks\n * - If set to `true`, virtual module IDs will be prefixed with the string `powerlines-virtual:`.\n * - If set to `false`, no prefix will be added to virtual module IDs.\n *\n * @defaultValue true\n */\n prefix?: boolean;\n}\n\nconst VIRTUAL_MODULE_PREFIX = \"powerlines-virtual:\";\nconst VIRTUAL_MODULE_PREFIX_REGEX = /^powerlines-virtual:/;\n\n/**\n * Creates the module resolution hook functions for a Powerlines unplugin plugin instance.\n *\n * @remarks\n * This includes the `resolveId` and `load` hooks.\n *\n * @see https://rollupjs.org/plugin-development/#resolveid\n * @see https://rollupjs.org/plugin-development/#load\n *\n * @param context - The plugin context.\n * @param options - Options for creating the module resolution functions.\n * @returns The module resolution hooks (`resolveId` and `load`).\n */\nexport function createUnpluginModuleResolutionFunctions<\n TContext extends PluginContext = PluginContext\n>(\n context: TContext,\n options: CreateUnpluginModuleResolutionFunctionsOptions = {}\n): Pick<UnpluginOptions, \"resolveId\" | \"load\"> {\n const ctx = context as unknown as UNSAFE_PluginContext;\n\n return {\n async resolveId(\n this: UnpluginBuildContext & UnpluginContext,\n id: string,\n importer?: string,\n opts: {\n isEntry: boolean;\n } = { isEntry: false }\n ): Promise<string | ResolveResult | null | undefined> {\n let result = await ctx.$$internal.callHook(\n \"resolveId\",\n {\n sequential: true,\n result: \"first\",\n order: \"pre\"\n },\n id,\n importer,\n opts\n );\n if (isSetString(result)) {\n return result;\n } else if (isSetObject(result)) {\n return {\n ...result,\n id:\n result.virtual && options.prefix !== false\n ? `${VIRTUAL_MODULE_PREFIX}${result.id}`\n : result.id\n };\n }\n\n result = await ctx.$$internal.callHook(\n \"resolveId\",\n {\n sequential: true,\n result: \"first\",\n order: \"normal\"\n },\n id,\n importer,\n opts\n );\n if (isSetString(result)) {\n return result;\n } else if (isSetObject(result)) {\n return {\n ...result,\n id:\n result.virtual && options.prefix !== false\n ? `${VIRTUAL_MODULE_PREFIX}${result.id}`\n : result.id\n };\n }\n\n result = await ctx.resolve(id, importer, { isFile: true, ...opts });\n if (isSetObject(result)) {\n return {\n ...result,\n id:\n result.virtual && options.prefix !== false\n ? `${VIRTUAL_MODULE_PREFIX}${result.id}`\n : result.id\n };\n }\n\n result = await ctx.$$internal.callHook(\n \"resolveId\",\n {\n sequential: true,\n result: \"first\",\n order: \"post\"\n },\n id,\n importer,\n opts\n );\n if (isSetString(result)) {\n return result;\n } else if (isSetObject(result)) {\n return {\n ...result,\n id:\n result.virtual && options.prefix !== false\n ? `${VIRTUAL_MODULE_PREFIX}${result.id}`\n : result.id\n };\n }\n\n return null;\n },\n load: {\n filter:\n options.prefix !== false\n ? {\n id: {\n include: [VIRTUAL_MODULE_PREFIX_REGEX]\n }\n }\n : undefined,\n async handler(\n this: UnpluginBuildContext & UnpluginContext,\n id: string\n ): Promise<LoadResult | null | undefined> {\n const moduleId =\n options.prefix !== false ? id.replace(VIRTUAL_MODULE_PREFIX, \"\") : id;\n\n let result = await ctx.$$internal.callHook(\n \"load\",\n {\n sequential: true,\n result: \"first\",\n order: \"pre\"\n },\n moduleId\n );\n if (result) {\n return result;\n }\n\n result = await ctx.$$internal.callHook(\n \"load\",\n {\n sequential: true,\n result: \"first\",\n order: \"normal\"\n },\n moduleId\n );\n if (result) {\n return result;\n }\n\n result = await ctx.load(moduleId);\n if (result) {\n return result;\n }\n\n return ctx.$$internal.callHook(\n \"load\",\n {\n sequential: true,\n result: \"first\",\n order: \"post\"\n },\n moduleId\n );\n }\n }\n };\n}\n"],"mappings":";;;;AA0CA,MAAM,wBAAwB;AAC9B,MAAM,8BAA8B;;;;;;;;;;;;;;AAepC,SAAgB,wCAGd,SACA,UAA0D,EAAE,EACf;CAC7C,MAAM,MAAM;AAEZ,QAAO;EACL,MAAM,UAEJ,IACA,UACA,OAEI,EAAE,SAAS,OAAO,EAC8B;GACpD,IAAI,SAAS,MAAM,IAAI,WAAW,SAChC,aACA;IACE,YAAY;IACZ,QAAQ;IACR,OAAO;IACR,EACD,IACA,UACA,KACD;AACD,OAAI,YAAY,OAAO,CACrB,QAAO;YACE,YAAY,OAAO,CAC5B,QAAO;IACL,GAAG;IACH,IACE,OAAO,WAAW,QAAQ,WAAW,QACjC,GAAG,wBAAwB,OAAO,OAClC,OAAO;IACd;AAGH,YAAS,MAAM,IAAI,WAAW,SAC5B,aACA;IACE,YAAY;IACZ,QAAQ;IACR,OAAO;IACR,EACD,IACA,UACA,KACD;AACD,OAAI,YAAY,OAAO,CACrB,QAAO;YACE,YAAY,OAAO,CAC5B,QAAO;IACL,GAAG;IACH,IACE,OAAO,WAAW,QAAQ,WAAW,QACjC,GAAG,wBAAwB,OAAO,OAClC,OAAO;IACd;AAGH,YAAS,MAAM,IAAI,QAAQ,IAAI,UAAU;IAAE,QAAQ;IAAM,GAAG;IAAM,CAAC;AACnE,OAAI,YAAY,OAAO,CACrB,QAAO;IACL,GAAG;IACH,IACE,OAAO,WAAW,QAAQ,WAAW,QACjC,GAAG,wBAAwB,OAAO,OAClC,OAAO;IACd;AAGH,YAAS,MAAM,IAAI,WAAW,SAC5B,aACA;IACE,YAAY;IACZ,QAAQ;IACR,OAAO;IACR,EACD,IACA,UACA,KACD;AACD,OAAI,YAAY,OAAO,CACrB,QAAO;YACE,YAAY,OAAO,CAC5B,QAAO;IACL,GAAG;IACH,IACE,OAAO,WAAW,QAAQ,WAAW,QACjC,GAAG,wBAAwB,OAAO,OAClC,OAAO;IACd;AAGH,UAAO;;EAET,MAAM;GACJ,QACE,QAAQ,WAAW,QACf,EACE,IAAI,EACF,SAAS,CAAC,4BAA4B,EACvC,EACF,GACD;GACN,MAAM,QAEJ,IACwC;IACxC,MAAM,WACJ,QAAQ,WAAW,QAAQ,GAAG,QAAQ,uBAAuB,GAAG,GAAG;IAErE,IAAI,SAAS,MAAM,IAAI,WAAW,SAChC,QACA;KACE,YAAY;KACZ,QAAQ;KACR,OAAO;KACR,EACD,SACD;AACD,QAAI,OACF,QAAO;AAGT,aAAS,MAAM,IAAI,WAAW,SAC5B,QACA;KACE,YAAY;KACZ,QAAQ;KACR,OAAO;KACR,EACD,SACD;AACD,QAAI,OACF,QAAO;AAGT,aAAS,MAAM,IAAI,KAAK,SAAS;AACjC,QAAI,OACF,QAAO;AAGT,WAAO,IAAI,WAAW,SACpB,QACA;KACE,YAAY;KACZ,QAAQ;KACR,OAAO;KACR,EACD,SACD;;GAEJ;EACF"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@powerlines/core",
3
- "version": "0.2.11",
3
+ "version": "0.2.13",
4
4
  "private": false,
5
5
  "description": "An internal core package for Powerlines - please use the `powerlines` package for public usage.",
6
6
  "homepage": "https://stormsoftware.com",
@@ -518,11 +518,11 @@
518
518
  "@storm-software/testing-tools": "^1.119.96",
519
519
  "@stryke/types": "^0.10.50",
520
520
  "@types/diff-match-patch": "^1.0.36",
521
- "@types/node": "^25.3.5",
521
+ "@types/node": "^25.4.0",
522
522
  "@types/semver": "^7.7.1",
523
523
  "tsdown": "^0.17.2",
524
524
  "typescript": "^5.9.3"
525
525
  },
526
526
  "publishConfig": { "access": "public" },
527
- "gitHead": "fbf339f9cac1fe1e5e99685befd5712c702e5baa"
527
+ "gitHead": "dde0f2e2684c65303dc81833f1d39c2c77910e22"
528
528
  }