@powerlines/plugin-unbuild 0.5.555 → 0.5.557

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.
@@ -1,5 +1,5 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2
- const require_resolve_options = require('../resolve-options-CjKawNtV.cjs');
2
+ const require_resolve_options = require('../resolve-options-B2bmiwoX.cjs');
3
3
 
4
4
  exports.DEFAULT_UNBUILD_CONFIG = require_resolve_options.DEFAULT_UNBUILD_CONFIG;
5
5
  exports.resolveOptions = require_resolve_options.resolveOptions;
@@ -1,3 +1,3 @@
1
- import { i as unbuildLoader, n as resolveOptions, t as DEFAULT_UNBUILD_CONFIG } from "../resolve-options-DIAFBMGd.mjs";
1
+ import { DEFAULT_UNBUILD_CONFIG, resolveOptions, unbuildLoader } from "./resolve-options.mjs";
2
2
 
3
3
  export { DEFAULT_UNBUILD_CONFIG, resolveOptions, unbuildLoader };
@@ -1,5 +1,5 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2
- const require_resolve_options = require('../resolve-options-CjKawNtV.cjs');
2
+ const require_resolve_options = require('../resolve-options-B2bmiwoX.cjs');
3
3
 
4
4
  exports.DEFAULT_UNBUILD_CONFIG = require_resolve_options.DEFAULT_UNBUILD_CONFIG;
5
5
  exports.resolveOptions = require_resolve_options.resolveOptions;
@@ -1,3 +1,123 @@
1
- import { i as unbuildLoader, n as resolveOptions, t as DEFAULT_UNBUILD_CONFIG } from "../resolve-options-DIAFBMGd.mjs";
1
+ import { getString } from "@powerlines/core/lib/utilities/source-file";
2
+ import { resolveOptions as resolveOptions$1 } from "@powerlines/unplugin/rollup";
3
+ import { appendPath, relativePath } from "@stryke/path";
4
+ import { joinPaths } from "@stryke/path/join-paths";
5
+ import defu from "defu";
6
+ import { transform } from "esbuild";
2
7
 
3
- export { DEFAULT_UNBUILD_CONFIG, resolveOptions, unbuildLoader };
8
+ //#region src/helpers/resolve-options.ts
9
+ const DEFAULT_UNBUILD_CONFIG = {
10
+ dts: true,
11
+ clean: false,
12
+ includeSrc: false,
13
+ treeShaking: true,
14
+ splitting: true,
15
+ stub: false,
16
+ watchOptions: {},
17
+ outputPath: "dist",
18
+ generatePackageJson: true,
19
+ banner: " ",
20
+ rollup: {
21
+ dts: {},
22
+ emitCJS: true,
23
+ replace: {},
24
+ resolve: {},
25
+ json: {},
26
+ esbuild: { target: "es2020" },
27
+ commonjs: {},
28
+ alias: {}
29
+ }
30
+ };
31
+ const unbuildLoader = (context) => {
32
+ return async (input, { options }) => {
33
+ if (!/\.(?:c|m)?[jt]sx?$/.test(input.path) || /\.d\.[cm]?ts$/.test(input.path)) return;
34
+ const output = [];
35
+ let contents = await input.getContents();
36
+ if (options.declaration && !input.srcPath?.match(/\.d\.[cm]?ts$/)) {
37
+ const extension = `.d.${input.srcPath?.match(/(?<=\.)(?:c|m)(?=[jt]s$)/)?.[0] || ""}ts`;
38
+ output.push({
39
+ contents,
40
+ srcPath: input.srcPath,
41
+ path: input.path,
42
+ extension,
43
+ declaration: true
44
+ });
45
+ }
46
+ let transformed = contents;
47
+ let result = await context.callHook("transform", {
48
+ sequential: true,
49
+ order: "pre"
50
+ }, transformed, input.path);
51
+ if (result) transformed = result;
52
+ result = await context.callHook("transform", {
53
+ sequential: true,
54
+ order: "normal"
55
+ }, getString(transformed), input.path);
56
+ if (result) transformed = result;
57
+ result = await context.callHook("transform", {
58
+ sequential: true,
59
+ order: "post"
60
+ }, getString(transformed), input.path);
61
+ if (result) transformed = result;
62
+ if ([
63
+ ".ts",
64
+ ".mts",
65
+ ".cts"
66
+ ].includes(input.extension)) contents = await transform(getString(transformed), {
67
+ ...Object.fromEntries(Object.entries(options.esbuild ?? {}).filter(([key]) => key !== "absPaths")),
68
+ loader: "ts"
69
+ }).then((r) => r.code);
70
+ else if ([".tsx", ".jsx"].includes(input.extension)) contents = await transform(getString(transformed), {
71
+ loader: input.extension === ".tsx" ? "tsx" : "jsx",
72
+ ...Object.fromEntries(Object.entries(options.esbuild ?? {}).filter(([key]) => key !== "absPaths"))
73
+ }).then((r) => r.code);
74
+ const isCjs = options.format === "cjs";
75
+ if (isCjs) contents = context.resolver.transform({
76
+ source: contents,
77
+ retainLines: false
78
+ }).replace(/^exports.default = /gm, "module.exports = ").replace(/^var _default = exports.default = /gm, "module.exports = ").replace("module.exports = void 0;", "");
79
+ let extension = isCjs ? ".js" : ".mjs";
80
+ if (options.ext) extension = options.ext.startsWith(".") ? options.ext : `.${options.ext}`;
81
+ output.push({
82
+ contents,
83
+ path: input.path,
84
+ extension
85
+ });
86
+ return output;
87
+ };
88
+ };
89
+ /**
90
+ * Extracts the unbuild configuration from the context.
91
+ *
92
+ * @param context - The build context.
93
+ * @returns The resolved unbuild configuration.
94
+ */
95
+ function resolveOptions(context) {
96
+ return defu({ alias: context.alias }, context.config.unbuild ? context.config.unbuild : {}, {
97
+ projectName: context.config.name,
98
+ name: context.config.name,
99
+ orgName: context.config.organization,
100
+ sourceRoot: joinPaths(context.config.root, "src"),
101
+ projectRoot: context.config.root,
102
+ outputPath: relativePath(appendPath(context.config.root, context.config.cwd), context.config.output.path),
103
+ platform: context.config.platform,
104
+ external: context.builtins.reduce((ret, id) => {
105
+ if (!ret.includes(id)) ret.push(id);
106
+ return ret;
107
+ }, context.config.resolve.external ?? []),
108
+ loaders: [unbuildLoader(context)],
109
+ jiti: {
110
+ interopDefault: true,
111
+ fsCache: joinPaths(context.envPaths.cache, "jiti"),
112
+ moduleCache: true
113
+ },
114
+ rollup: resolveOptions$1(context),
115
+ debug: context.config.mode === "development",
116
+ minify: context.config.output.minify,
117
+ sourcemap: context.config.output.sourceMap
118
+ }, DEFAULT_UNBUILD_CONFIG);
119
+ }
120
+
121
+ //#endregion
122
+ export { DEFAULT_UNBUILD_CONFIG, resolveOptions, unbuildLoader };
123
+ //# sourceMappingURL=resolve-options.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"resolve-options.mjs","names":["resolveRollupOptions"],"sources":["../../src/helpers/resolve-options.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 { getString } from \"@powerlines/core/lib/utilities/source-file\";\nimport { resolveOptions as resolveRollupOptions } from \"@powerlines/unplugin/rollup\";\nimport type {\n UnbuildOptions as ExternalUnbuildOptions,\n Loader,\n LoaderResult\n} from \"@storm-software/unbuild/types\";\nimport { appendPath, relativePath } from \"@stryke/path\";\nimport { joinPaths } from \"@stryke/path/join-paths\";\nimport defu from \"defu\";\nimport { transform } from \"esbuild\";\nimport type { Context, PluginContext } from \"powerlines\";\nimport { TransformResult } from \"unplugin\";\nimport { UnbuildPluginResolvedConfig } from \"../types\";\n\nexport const DEFAULT_UNBUILD_CONFIG = {\n dts: true,\n clean: false,\n includeSrc: false,\n treeShaking: true,\n splitting: true,\n stub: false,\n watchOptions: {},\n outputPath: \"dist\",\n generatePackageJson: true,\n banner: \" \",\n rollup: {\n dts: {},\n emitCJS: true,\n replace: {},\n resolve: {},\n json: {},\n esbuild: { target: \"es2020\" },\n commonjs: {},\n alias: {}\n }\n} as Partial<ExternalUnbuildOptions>;\n\nexport const unbuildLoader = (context: PluginContext): Loader => {\n return async (input, { options }) => {\n if (\n !/\\.(?:c|m)?[jt]sx?$/.test(input.path) ||\n /\\.d\\.[cm]?ts$/.test(input.path)\n ) {\n return;\n }\n\n const output: LoaderResult = [];\n\n let contents = await input.getContents();\n\n // declaration\n if (options.declaration && !input.srcPath?.match(/\\.d\\.[cm]?ts$/)) {\n const cm = input.srcPath?.match(/(?<=\\.)(?:c|m)(?=[jt]s$)/)?.[0] || \"\";\n const extension = `.d.${cm}ts`;\n output.push({\n contents,\n srcPath: input.srcPath,\n path: input.path,\n extension,\n declaration: true\n });\n }\n\n let transformed: TransformResult | string = contents;\n\n let result = await context.callHook(\n \"transform\",\n {\n sequential: true,\n order: \"pre\"\n },\n transformed,\n input.path\n );\n if (result) {\n transformed = result;\n }\n\n result = await context.callHook(\n \"transform\",\n {\n sequential: true,\n order: \"normal\"\n },\n getString(transformed),\n input.path\n );\n if (result) {\n transformed = result;\n }\n\n result = await context.callHook(\n \"transform\",\n {\n sequential: true,\n order: \"post\"\n },\n getString(transformed),\n input.path\n );\n if (result) {\n transformed = result;\n }\n\n // typescript => js\n if ([\".ts\", \".mts\", \".cts\"].includes(input.extension)) {\n contents = await transform(getString(transformed), {\n ...Object.fromEntries(\n Object.entries(options.esbuild ?? {}).filter(\n ([key]) => key !== \"absPaths\"\n )\n ),\n loader: \"ts\"\n }).then(r => r.code);\n } else if ([\".tsx\", \".jsx\"].includes(input.extension)) {\n contents = await transform(getString(transformed), {\n loader: input.extension === \".tsx\" ? \"tsx\" : \"jsx\",\n ...Object.fromEntries(\n Object.entries(options.esbuild ?? {}).filter(\n ([key]) => key !== \"absPaths\"\n )\n )\n }).then(r => r.code);\n }\n\n // esm => cjs\n const isCjs = options.format === \"cjs\";\n if (isCjs) {\n contents = context.resolver\n .transform({\n source: contents,\n retainLines: false\n })\n .replace(/^exports.default = /gm, \"module.exports = \")\n .replace(/^var _default = exports.default = /gm, \"module.exports = \")\n .replace(\"module.exports = void 0;\", \"\");\n }\n\n let extension = isCjs ? \".js\" : \".mjs\"; // TODO: Default to .cjs in next major version\n if (options.ext) {\n extension = options.ext.startsWith(\".\") ? options.ext : `.${options.ext}`;\n }\n\n output.push({\n contents,\n path: input.path,\n extension\n });\n\n return output;\n };\n};\n\n/**\n * Extracts the unbuild configuration from the context.\n *\n * @param context - The build context.\n * @returns The resolved unbuild configuration.\n */\nexport function resolveOptions(context: Context): ExternalUnbuildOptions {\n return defu(\n {\n alias: context.alias\n },\n (context.config as UnbuildPluginResolvedConfig).unbuild\n ? (context.config as UnbuildPluginResolvedConfig).unbuild\n : {},\n {\n projectName: context.config.name,\n name: context.config.name,\n orgName: context.config.organization,\n sourceRoot: joinPaths(context.config.root, \"src\"),\n projectRoot: context.config.root,\n outputPath: relativePath(\n appendPath(context.config.root, context.config.cwd),\n context.config.output.path\n ),\n platform: context.config.platform,\n external: context.builtins.reduce((ret, id) => {\n if (!ret.includes(id)) {\n ret.push(id);\n }\n\n return ret;\n }, context.config.resolve.external ?? []),\n loaders: [unbuildLoader(context as PluginContext)],\n jiti: {\n interopDefault: true,\n fsCache: joinPaths(context.envPaths.cache, \"jiti\"),\n moduleCache: true\n },\n rollup: resolveRollupOptions(context) as any,\n debug: context.config.mode === \"development\",\n minify: context.config.output.minify,\n sourcemap: context.config.output.sourceMap\n },\n DEFAULT_UNBUILD_CONFIG\n ) as ExternalUnbuildOptions;\n}\n"],"mappings":";;;;;;;;AAiCA,MAAa,yBAAyB;CACpC,KAAK;CACL,OAAO;CACP,YAAY;CACZ,aAAa;CACb,WAAW;CACX,MAAM;CACN,cAAc,CAAC;CACf,YAAY;CACZ,qBAAqB;CACrB,QAAQ;CACR,QAAQ;EACN,KAAK,CAAC;EACN,SAAS;EACT,SAAS,CAAC;EACV,SAAS,CAAC;EACV,MAAM,CAAC;EACP,SAAS,EAAE,QAAQ,SAAS;EAC5B,UAAU,CAAC;EACX,OAAO,CAAC;CACV;AACF;AAEA,MAAa,iBAAiB,YAAmC;CAC/D,OAAO,OAAO,OAAO,EAAE,cAAc;EACnC,IACE,CAAC,qBAAqB,KAAK,MAAM,IAAI,KACrC,gBAAgB,KAAK,MAAM,IAAI,GAE/B;EAGF,MAAM,SAAuB,CAAC;EAE9B,IAAI,WAAW,MAAM,MAAM,YAAY;EAGvC,IAAI,QAAQ,eAAe,CAAC,MAAM,SAAS,MAAM,eAAe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wCAAwC,mBAAmB,EACnE,QAAQ,4BAA4B,EAAE;EAG3C,IAAI,YAAY,QAAQ,QAAQ;EAChC,IAAI,QAAQ,KACV,YAAY,QAAQ,IAAI,WAAW,GAAG,IAAI,QAAQ,MAAM,IAAI,QAAQ;EAGtE,OAAO,KAAK;GACV;GACA,MAAM,MAAM;GACZ;EACF,CAAC;EAED,OAAO;CACT;AACF;;;;;;;AAQA,SAAgB,eAAe,SAA0C;CACvE,OAAO,KACL,EACE,OAAO,QAAQ,MACjB,GACC,QAAQ,OAAuC,UAC3C,QAAQ,OAAuC,UAChD,CAAC,GACL;EACE,aAAa,QAAQ,OAAO;EAC5B,MAAM,QAAQ,OAAO;EACrB,SAAS,QAAQ,OAAO;EACxB,YAAY,UAAU,QAAQ,OAAO,MAAM,KAAK;EAChD,aAAa,QAAQ,OAAO;EAC5B,YAAY,aACV,WAAW,QAAQ,OAAO,MAAM,QAAQ,OAAO,GAAG,GAClD,QAAQ,OAAO,OAAO,IACxB;EACA,UAAU,QAAQ,OAAO;EACzB,UAAU,QAAQ,SAAS,QAAQ,KAAK,OAAO;GAC7C,IAAI,CAAC,IAAI,SAAS,EAAE,GAClB,IAAI,KAAK,EAAE;GAGb,OAAO;EACT,GAAG,QAAQ,OAAO,QAAQ,YAAY,CAAC,CAAC;EACxC,SAAS,CAAC,cAAc,OAAwB,CAAC;EACjD,MAAM;GACJ,gBAAgB;GAChB,SAAS,UAAU,QAAQ,SAAS,OAAO,MAAM;GACjD,aAAa;EACf;EACA,QAAQA,iBAAqB,OAAO;EACpC,OAAO,QAAQ,OAAO,SAAS;EAC/B,QAAQ,QAAQ,OAAO,OAAO;EAC9B,WAAW,QAAQ,OAAO,OAAO;CACnC,GACA,sBACF;AACF"}
package/dist/index.cjs CHANGED
@@ -1,5 +1,5 @@
1
1
  Object.defineProperties(exports, { __esModule: { value: true }, [Symbol.toStringTag]: { value: 'Module' } });
2
- const require_resolve_options = require('./resolve-options-CjKawNtV.cjs');
2
+ const require_resolve_options = require('./resolve-options-B2bmiwoX.cjs');
3
3
  require('./helpers/index.cjs');
4
4
  let _storm_software_unbuild = require("@storm-software/unbuild");
5
5
  let powerlines_plugin_utils = require("powerlines/plugin-utils");
package/dist/index.mjs CHANGED
@@ -1,4 +1,4 @@
1
- import { i as unbuildLoader, n as resolveOptions, t as DEFAULT_UNBUILD_CONFIG } from "./resolve-options-DIAFBMGd.mjs";
1
+ import { DEFAULT_UNBUILD_CONFIG, resolveOptions, unbuildLoader } from "./helpers/resolve-options.mjs";
2
2
  import "./helpers/index.mjs";
3
3
  import { build } from "@storm-software/unbuild";
4
4
  import { formatConfig } from "powerlines/plugin-utils";
@@ -5,19 +5,6 @@ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
5
  var __getOwnPropNames = Object.getOwnPropertyNames;
6
6
  var __getProtoOf = Object.getPrototypeOf;
7
7
  var __hasOwnProp = Object.prototype.hasOwnProperty;
8
- var __exportAll = (all, no_symbols) => {
9
- let target = {};
10
- for (var name in all) {
11
- __defProp(target, name, {
12
- get: all[name],
13
- enumerable: true
14
- });
15
- }
16
- if (!no_symbols) {
17
- __defProp(target, Symbol.toStringTag, { value: "Module" });
18
- }
19
- return target;
20
- };
21
8
  var __copyProps = (to, from, except, desc) => {
22
9
  if (from && typeof from === "object" || typeof from === "function") {
23
10
  for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
@@ -47,11 +34,6 @@ defu = __toESM(defu, 1);
47
34
  let esbuild = require("esbuild");
48
35
 
49
36
  //#region src/helpers/resolve-options.ts
50
- var resolve_options_exports = /* @__PURE__ */ __exportAll({
51
- DEFAULT_UNBUILD_CONFIG: () => DEFAULT_UNBUILD_CONFIG,
52
- resolveOptions: () => resolveOptions,
53
- unbuildLoader: () => unbuildLoader
54
- });
55
37
  const DEFAULT_UNBUILD_CONFIG = {
56
38
  dts: true,
57
39
  clean: false,
@@ -177,12 +159,6 @@ Object.defineProperty(exports, 'resolveOptions', {
177
159
  return resolveOptions;
178
160
  }
179
161
  });
180
- Object.defineProperty(exports, 'resolve_options_exports', {
181
- enumerable: true,
182
- get: function () {
183
- return resolve_options_exports;
184
- }
185
- });
186
162
  Object.defineProperty(exports, 'unbuildLoader', {
187
163
  enumerable: true,
188
164
  get: function () {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@powerlines/plugin-unbuild",
3
- "version": "0.5.555",
3
+ "version": "0.5.557",
4
4
  "private": false,
5
5
  "description": "A package containing a Powerlines plugin to build projects using Unbuild.",
6
6
  "keywords": ["unbuild", "powerlines", "storm-software", "powerlines-plugin"],
@@ -69,14 +69,14 @@
69
69
  "typings": "dist/index.d.mts",
70
70
  "files": ["dist"],
71
71
  "dependencies": {
72
- "@powerlines/core": "^0.48.32",
73
- "@powerlines/unplugin": "^0.0.80",
72
+ "@powerlines/core": "^0.48.34",
73
+ "@powerlines/unplugin": "^0.0.82",
74
74
  "@stryke/helpers": "^0.10.22",
75
75
  "@stryke/path": "^0.29.9",
76
76
  "@stryke/type-checks": "^0.6.15",
77
77
  "defu": "^6.1.7",
78
78
  "esbuild": "^0.27.7",
79
- "powerlines": "^0.47.99",
79
+ "powerlines": "^0.47.101",
80
80
  "unplugin": "^3.0.0"
81
81
  },
82
82
  "devDependencies": {
@@ -86,5 +86,5 @@
86
86
  "peerDependencies": { "@storm-software/unbuild": ">=0.57.0" },
87
87
  "peerDependenciesMeta": { "@storm-software/unbuild": { "optional": false } },
88
88
  "publishConfig": { "access": "public" },
89
- "gitHead": "11b392585b2086772822dd103176c9d58e30dc9c"
89
+ "gitHead": "64a604fd5da7312baeeb58dfcef0fd3ace15174e"
90
90
  }
@@ -1,15 +0,0 @@
1
- const require_resolve_options = require('../resolve-options-CjKawNtV.cjs');
2
- let vitest = require("vitest");
3
-
4
- //#region src/helpers/resolve-options.test.ts
5
- (0, vitest.describe)("plugins/plugin-unbuild/src/helpers/resolve-options.ts", () => {
6
- (0, vitest.it)("loads module exports", () => {
7
- (0, vitest.expect)(require_resolve_options.resolve_options_exports).toBeDefined();
8
- (0, vitest.expect)(typeof require_resolve_options.resolve_options_exports).toBe("object");
9
- });
10
- (0, vitest.it)("has at least one runtime export", () => {
11
- (0, vitest.expect)(Object.keys(require_resolve_options.resolve_options_exports).length).toBeGreaterThan(0);
12
- });
13
- });
14
-
15
- //#endregion
@@ -1 +0,0 @@
1
- export { };
@@ -1 +0,0 @@
1
- export { };
@@ -1,17 +0,0 @@
1
- import { r as resolve_options_exports } from "../resolve-options-DIAFBMGd.mjs";
2
- import { describe, expect, it } from "vitest";
3
-
4
- //#region src/helpers/resolve-options.test.ts
5
- describe("plugins/plugin-unbuild/src/helpers/resolve-options.ts", () => {
6
- it("loads module exports", () => {
7
- expect(resolve_options_exports).toBeDefined();
8
- expect(typeof resolve_options_exports).toBe("object");
9
- });
10
- it("has at least one runtime export", () => {
11
- expect(Object.keys(resolve_options_exports).length).toBeGreaterThan(0);
12
- });
13
- });
14
-
15
- //#endregion
16
- export { };
17
- //# sourceMappingURL=resolve-options.test.mjs.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"resolve-options.test.mjs","names":["moduleExports"],"sources":["../../src/helpers/resolve-options.test.ts"],"sourcesContent":["import { describe, expect, it } from \"vitest\";\nimport * as moduleExports from \"./resolve-options\";\n\ndescribe(\"plugins/plugin-unbuild/src/helpers/resolve-options.ts\", () => {\n it(\"loads module exports\", () => {\n expect(moduleExports).toBeDefined();\n expect(typeof moduleExports).toBe(\"object\");\n });\n\n it(\"has at least one runtime export\", () => {\n expect(Object.keys(moduleExports).length).toBeGreaterThan(0);\n });\n});\n"],"mappings":";;;;AAGA,SAAS,+DAA+D;CACtE,GAAG,8BAA8B;EAC/B,OAAOA,uBAAa,EAAE,YAAY;EAClC,OAAO,OAAOA,uBAAa,EAAE,KAAK,QAAQ;CAC5C,CAAC;CAED,GAAG,yCAAyC;EAC1C,OAAO,OAAO,KAAKA,uBAAa,EAAE,MAAM,EAAE,gBAAgB,CAAC;CAC7D,CAAC;AACH,CAAC"}
@@ -1,145 +0,0 @@
1
- import { getString } from "@powerlines/core/lib/utilities/source-file";
2
- import { resolveOptions } from "@powerlines/unplugin/rollup";
3
- import { appendPath, relativePath } from "@stryke/path";
4
- import { joinPaths } from "@stryke/path/join-paths";
5
- import defu from "defu";
6
- import { transform } from "esbuild";
7
-
8
- //#region \0rolldown/runtime.js
9
- var __defProp = Object.defineProperty;
10
- var __exportAll = (all, no_symbols) => {
11
- let target = {};
12
- for (var name in all) {
13
- __defProp(target, name, {
14
- get: all[name],
15
- enumerable: true
16
- });
17
- }
18
- if (!no_symbols) {
19
- __defProp(target, Symbol.toStringTag, { value: "Module" });
20
- }
21
- return target;
22
- };
23
-
24
- //#endregion
25
- //#region src/helpers/resolve-options.ts
26
- var resolve_options_exports = /* @__PURE__ */ __exportAll({
27
- DEFAULT_UNBUILD_CONFIG: () => DEFAULT_UNBUILD_CONFIG,
28
- resolveOptions: () => resolveOptions$1,
29
- unbuildLoader: () => unbuildLoader
30
- });
31
- const DEFAULT_UNBUILD_CONFIG = {
32
- dts: true,
33
- clean: false,
34
- includeSrc: false,
35
- treeShaking: true,
36
- splitting: true,
37
- stub: false,
38
- watchOptions: {},
39
- outputPath: "dist",
40
- generatePackageJson: true,
41
- banner: " ",
42
- rollup: {
43
- dts: {},
44
- emitCJS: true,
45
- replace: {},
46
- resolve: {},
47
- json: {},
48
- esbuild: { target: "es2020" },
49
- commonjs: {},
50
- alias: {}
51
- }
52
- };
53
- const unbuildLoader = (context) => {
54
- return async (input, { options }) => {
55
- if (!/\.(?:c|m)?[jt]sx?$/.test(input.path) || /\.d\.[cm]?ts$/.test(input.path)) return;
56
- const output = [];
57
- let contents = await input.getContents();
58
- if (options.declaration && !input.srcPath?.match(/\.d\.[cm]?ts$/)) {
59
- const extension = `.d.${input.srcPath?.match(/(?<=\.)(?:c|m)(?=[jt]s$)/)?.[0] || ""}ts`;
60
- output.push({
61
- contents,
62
- srcPath: input.srcPath,
63
- path: input.path,
64
- extension,
65
- declaration: true
66
- });
67
- }
68
- let transformed = contents;
69
- let result = await context.callHook("transform", {
70
- sequential: true,
71
- order: "pre"
72
- }, transformed, input.path);
73
- if (result) transformed = result;
74
- result = await context.callHook("transform", {
75
- sequential: true,
76
- order: "normal"
77
- }, getString(transformed), input.path);
78
- if (result) transformed = result;
79
- result = await context.callHook("transform", {
80
- sequential: true,
81
- order: "post"
82
- }, getString(transformed), input.path);
83
- if (result) transformed = result;
84
- if ([
85
- ".ts",
86
- ".mts",
87
- ".cts"
88
- ].includes(input.extension)) contents = await transform(getString(transformed), {
89
- ...Object.fromEntries(Object.entries(options.esbuild ?? {}).filter(([key]) => key !== "absPaths")),
90
- loader: "ts"
91
- }).then((r) => r.code);
92
- else if ([".tsx", ".jsx"].includes(input.extension)) contents = await transform(getString(transformed), {
93
- loader: input.extension === ".tsx" ? "tsx" : "jsx",
94
- ...Object.fromEntries(Object.entries(options.esbuild ?? {}).filter(([key]) => key !== "absPaths"))
95
- }).then((r) => r.code);
96
- const isCjs = options.format === "cjs";
97
- if (isCjs) contents = context.resolver.transform({
98
- source: contents,
99
- retainLines: false
100
- }).replace(/^exports.default = /gm, "module.exports = ").replace(/^var _default = exports.default = /gm, "module.exports = ").replace("module.exports = void 0;", "");
101
- let extension = isCjs ? ".js" : ".mjs";
102
- if (options.ext) extension = options.ext.startsWith(".") ? options.ext : `.${options.ext}`;
103
- output.push({
104
- contents,
105
- path: input.path,
106
- extension
107
- });
108
- return output;
109
- };
110
- };
111
- /**
112
- * Extracts the unbuild configuration from the context.
113
- *
114
- * @param context - The build context.
115
- * @returns The resolved unbuild configuration.
116
- */
117
- function resolveOptions$1(context) {
118
- return defu({ alias: context.alias }, context.config.unbuild ? context.config.unbuild : {}, {
119
- projectName: context.config.name,
120
- name: context.config.name,
121
- orgName: context.config.organization,
122
- sourceRoot: joinPaths(context.config.root, "src"),
123
- projectRoot: context.config.root,
124
- outputPath: relativePath(appendPath(context.config.root, context.config.cwd), context.config.output.path),
125
- platform: context.config.platform,
126
- external: context.builtins.reduce((ret, id) => {
127
- if (!ret.includes(id)) ret.push(id);
128
- return ret;
129
- }, context.config.resolve.external ?? []),
130
- loaders: [unbuildLoader(context)],
131
- jiti: {
132
- interopDefault: true,
133
- fsCache: joinPaths(context.envPaths.cache, "jiti"),
134
- moduleCache: true
135
- },
136
- rollup: resolveOptions(context),
137
- debug: context.config.mode === "development",
138
- minify: context.config.output.minify,
139
- sourcemap: context.config.output.sourceMap
140
- }, DEFAULT_UNBUILD_CONFIG);
141
- }
142
-
143
- //#endregion
144
- export { unbuildLoader as i, resolveOptions$1 as n, resolve_options_exports as r, DEFAULT_UNBUILD_CONFIG as t };
145
- //# sourceMappingURL=resolve-options-DIAFBMGd.mjs.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"resolve-options-DIAFBMGd.mjs","names":["resolveOptions","resolveRollupOptions"],"sources":["../src/helpers/resolve-options.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 { getString } from \"@powerlines/core/lib/utilities/source-file\";\nimport { resolveOptions as resolveRollupOptions } from \"@powerlines/unplugin/rollup\";\nimport type {\n UnbuildOptions as ExternalUnbuildOptions,\n Loader,\n LoaderResult\n} from \"@storm-software/unbuild/types\";\nimport { appendPath, relativePath } from \"@stryke/path\";\nimport { joinPaths } from \"@stryke/path/join-paths\";\nimport defu from \"defu\";\nimport { transform } from \"esbuild\";\nimport type { Context, PluginContext } from \"powerlines\";\nimport { TransformResult } from \"unplugin\";\nimport { UnbuildPluginResolvedConfig } from \"../types\";\n\nexport const DEFAULT_UNBUILD_CONFIG = {\n dts: true,\n clean: false,\n includeSrc: false,\n treeShaking: true,\n splitting: true,\n stub: false,\n watchOptions: {},\n outputPath: \"dist\",\n generatePackageJson: true,\n banner: \" \",\n rollup: {\n dts: {},\n emitCJS: true,\n replace: {},\n resolve: {},\n json: {},\n esbuild: { target: \"es2020\" },\n commonjs: {},\n alias: {}\n }\n} as Partial<ExternalUnbuildOptions>;\n\nexport const unbuildLoader = (context: PluginContext): Loader => {\n return async (input, { options }) => {\n if (\n !/\\.(?:c|m)?[jt]sx?$/.test(input.path) ||\n /\\.d\\.[cm]?ts$/.test(input.path)\n ) {\n return;\n }\n\n const output: LoaderResult = [];\n\n let contents = await input.getContents();\n\n // declaration\n if (options.declaration && !input.srcPath?.match(/\\.d\\.[cm]?ts$/)) {\n const cm = input.srcPath?.match(/(?<=\\.)(?:c|m)(?=[jt]s$)/)?.[0] || \"\";\n const extension = `.d.${cm}ts`;\n output.push({\n contents,\n srcPath: input.srcPath,\n path: input.path,\n extension,\n declaration: true\n });\n }\n\n let transformed: TransformResult | string = contents;\n\n let result = await context.callHook(\n \"transform\",\n {\n sequential: true,\n order: \"pre\"\n },\n transformed,\n input.path\n );\n if (result) {\n transformed = result;\n }\n\n result = await context.callHook(\n \"transform\",\n {\n sequential: true,\n order: \"normal\"\n },\n getString(transformed),\n input.path\n );\n if (result) {\n transformed = result;\n }\n\n result = await context.callHook(\n \"transform\",\n {\n sequential: true,\n order: \"post\"\n },\n getString(transformed),\n input.path\n );\n if (result) {\n transformed = result;\n }\n\n // typescript => js\n if ([\".ts\", \".mts\", \".cts\"].includes(input.extension)) {\n contents = await transform(getString(transformed), {\n ...Object.fromEntries(\n Object.entries(options.esbuild ?? {}).filter(\n ([key]) => key !== \"absPaths\"\n )\n ),\n loader: \"ts\"\n }).then(r => r.code);\n } else if ([\".tsx\", \".jsx\"].includes(input.extension)) {\n contents = await transform(getString(transformed), {\n loader: input.extension === \".tsx\" ? \"tsx\" : \"jsx\",\n ...Object.fromEntries(\n Object.entries(options.esbuild ?? {}).filter(\n ([key]) => key !== \"absPaths\"\n )\n )\n }).then(r => r.code);\n }\n\n // esm => cjs\n const isCjs = options.format === \"cjs\";\n if (isCjs) {\n contents = context.resolver\n .transform({\n source: contents,\n retainLines: false\n })\n .replace(/^exports.default = /gm, \"module.exports = \")\n .replace(/^var _default = exports.default = /gm, \"module.exports = \")\n .replace(\"module.exports = void 0;\", \"\");\n }\n\n let extension = isCjs ? \".js\" : \".mjs\"; // TODO: Default to .cjs in next major version\n if (options.ext) {\n extension = options.ext.startsWith(\".\") ? options.ext : `.${options.ext}`;\n }\n\n output.push({\n contents,\n path: input.path,\n extension\n });\n\n return output;\n };\n};\n\n/**\n * Extracts the unbuild configuration from the context.\n *\n * @param context - The build context.\n * @returns The resolved unbuild configuration.\n */\nexport function resolveOptions(context: Context): ExternalUnbuildOptions {\n return defu(\n {\n alias: context.alias\n },\n (context.config as UnbuildPluginResolvedConfig).unbuild\n ? (context.config as UnbuildPluginResolvedConfig).unbuild\n : {},\n {\n projectName: context.config.name,\n name: context.config.name,\n orgName: context.config.organization,\n sourceRoot: joinPaths(context.config.root, \"src\"),\n projectRoot: context.config.root,\n outputPath: relativePath(\n appendPath(context.config.root, context.config.cwd),\n context.config.output.path\n ),\n platform: context.config.platform,\n external: context.builtins.reduce((ret, id) => {\n if (!ret.includes(id)) {\n ret.push(id);\n }\n\n return ret;\n }, context.config.resolve.external ?? []),\n loaders: [unbuildLoader(context as PluginContext)],\n jiti: {\n interopDefault: true,\n fsCache: joinPaths(context.envPaths.cache, \"jiti\"),\n moduleCache: true\n },\n rollup: resolveRollupOptions(context) as any,\n debug: context.config.mode === \"development\",\n minify: context.config.output.minify,\n sourcemap: context.config.output.sourceMap\n },\n DEFAULT_UNBUILD_CONFIG\n ) as ExternalUnbuildOptions;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAiCA,MAAa,yB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