@winner-fed/bundler-esbuild 0.19.4 → 1.0.0-rc.0

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,44 +1,22 @@
1
- var __defProp = Object.defineProperty;
2
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
- var __getOwnPropNames = Object.getOwnPropertyNames;
4
- var __hasOwnProp = Object.prototype.hasOwnProperty;
5
- var __export = (target, all) => {
6
- for (var name in all)
7
- __defProp(target, name, { get: all[name], enumerable: true });
8
- };
9
- var __copyProps = (to, from, except, desc) => {
10
- if (from && typeof from === "object" || typeof from === "function") {
11
- for (let key of __getOwnPropNames(from))
12
- if (!__hasOwnProp.call(to, key) && key !== except)
13
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
14
- }
15
- return to;
16
- };
17
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
18
-
19
- // src/plugins/externals.ts
20
- var externals_exports = {};
21
- __export(externals_exports, {
22
- default: () => externals_default
23
- });
24
- module.exports = __toCommonJS(externals_exports);
25
1
  var externals_default = (options) => {
26
- return {
27
- name: "externals",
28
- setup({ onLoad, onResolve }) {
29
- if (!options || Object.keys(options).length === 0) {
30
- return;
31
- }
32
- Object.keys(options).forEach((key) => {
33
- onResolve({ filter: new RegExp(`^${key}$`) }, (args) => ({
34
- path: args.path,
35
- namespace: key
36
- }));
37
- onLoad({ filter: /.*/, namespace: key }, () => ({
38
- contents: `module.export=${options[key]}`,
39
- loader: "js"
40
- }));
41
- });
42
- }
43
- };
2
+ return {
3
+ name: "externals",
4
+ setup({ onLoad, onResolve }) {
5
+ if (!options || Object.keys(options).length === 0) return;
6
+ Object.keys(options).forEach((key) => {
7
+ onResolve({ filter: new RegExp(`^${key}$`) }, (args) => ({
8
+ path: args.path,
9
+ namespace: key
10
+ }));
11
+ onLoad({
12
+ filter: /.*/,
13
+ namespace: key
14
+ }, () => ({
15
+ contents: `module.export=${options[key]}`,
16
+ loader: "js"
17
+ }));
18
+ });
19
+ }
20
+ };
44
21
  };
22
+ module.exports = externals_default;
@@ -1,9 +1,9 @@
1
1
  interface Options {
2
- alias: Record<string, string>;
2
+ alias: Record<string, string>;
3
3
  }
4
- export default class LessAliasPlugin {
5
- private options;
6
- constructor(options: Options);
7
- install(less: LessStatic, pluginManager: Less.PluginManager): void;
4
+ declare class LessAliasPlugin {
5
+ private options;
6
+ constructor(options: Options);
7
+ install(less: LessStatic, pluginManager: Less.PluginManager): void;
8
8
  }
9
- export {};
9
+ export = LessAliasPlugin;
@@ -1,100 +1,54 @@
1
- var __defProp = Object.defineProperty;
2
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
- var __getOwnPropNames = Object.getOwnPropertyNames;
4
- var __hasOwnProp = Object.prototype.hasOwnProperty;
5
- var __export = (target, all) => {
6
- for (var name in all)
7
- __defProp(target, name, { get: all[name], enumerable: true });
8
- };
9
- var __copyProps = (to, from, except, desc) => {
10
- if (from && typeof from === "object" || typeof from === "function") {
11
- for (let key of __getOwnPropNames(from))
12
- if (!__hasOwnProp.call(to, key) && key !== except)
13
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
14
- }
15
- return to;
16
- };
17
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
18
-
19
- // src/plugins/less-plugin-alias/index.ts
20
- var less_plugin_alias_exports = {};
21
- __export(less_plugin_alias_exports, {
22
- default: () => LessAliasPlugin
23
- });
24
- module.exports = __toCommonJS(less_plugin_alias_exports);
25
- var import_utils = require("@winner-fed/utils");
26
- var import_utils2 = require("./utils");
1
+ const require_plugins_less_plugin_alias_utils = require("./utils.js");
2
+ let _winner_fed_utils = require("@winner-fed/utils");
27
3
  function matches(pattern, importee) {
28
- if (pattern instanceof RegExp) {
29
- return pattern.test(importee);
30
- }
31
- if (importee.length < pattern.length) {
32
- return false;
33
- }
34
- if (importee === pattern) {
35
- return true;
36
- }
37
- return importee.startsWith(pattern + "/");
4
+ if (pattern instanceof RegExp) return pattern.test(importee);
5
+ if (importee.length < pattern.length) return false;
6
+ if (importee === pattern) return true;
7
+ return importee.startsWith(pattern + "/");
38
8
  }
39
9
  var LessAliasPlugin = class {
40
- constructor(options) {
41
- this.options = options;
42
- }
43
- install(less, pluginManager) {
44
- const alias = (0, import_utils2.parseAlias)(this.options.alias);
45
- function resolveId(filename) {
46
- if (!filename) {
47
- return null;
48
- }
49
- const matchedEntry = alias.find((entry) => matches(entry.find, filename));
50
- if (!matchedEntry) {
51
- return filename;
52
- }
53
- const resolvedPath = filename.replace(
54
- matchedEntry.find,
55
- matchedEntry.replacement
56
- );
57
- return resolvedPath;
58
- }
59
- class AliasePlugin extends less.FileManager {
60
- loadFile(filename, currentDirectory, options, enviroment) {
61
- let resolved;
62
- try {
63
- resolved = resolveId(filename);
64
- } catch (error) {
65
- import_utils.logger.error(error);
66
- }
67
- if (!resolved) {
68
- const error = new Error(
69
- `[less-plugin-alias]: '${filename}' not found.`
70
- );
71
- import_utils.logger.error(error);
72
- throw error;
73
- }
74
- return super.loadFile(resolved, currentDirectory, options, enviroment);
75
- }
76
- loadFileSync(filename, currentDirectory, options, enviroment) {
77
- let resolved;
78
- try {
79
- resolved = resolveId(filename);
80
- } catch (error) {
81
- import_utils.logger.error(error);
82
- }
83
- if (!resolved) {
84
- const error = new Error(
85
- `[less-plugin-alias]: '${filename}' not found.`
86
- );
87
- import_utils.logger.error(error);
88
- throw error;
89
- }
90
- return super.loadFileSync(
91
- resolved,
92
- currentDirectory,
93
- options,
94
- enviroment
95
- );
96
- }
97
- }
98
- pluginManager.addFileManager(new AliasePlugin());
99
- }
10
+ constructor(options) {
11
+ this.options = options;
12
+ }
13
+ install(less, pluginManager) {
14
+ const alias = require_plugins_less_plugin_alias_utils.parseAlias(this.options.alias);
15
+ function resolveId(filename) {
16
+ if (!filename) return null;
17
+ const matchedEntry = alias.find((entry) => matches(entry.find, filename));
18
+ if (!matchedEntry) return filename;
19
+ return filename.replace(matchedEntry.find, matchedEntry.replacement);
20
+ }
21
+ class AliasePlugin extends less.FileManager {
22
+ loadFile(filename, currentDirectory, options, enviroment) {
23
+ let resolved;
24
+ try {
25
+ resolved = resolveId(filename);
26
+ } catch (error) {
27
+ _winner_fed_utils.logger.error(error);
28
+ }
29
+ if (!resolved) {
30
+ const error = /* @__PURE__ */ new Error(`[less-plugin-alias]: '${filename}' not found.`);
31
+ _winner_fed_utils.logger.error(error);
32
+ throw error;
33
+ }
34
+ return super.loadFile(resolved, currentDirectory, options, enviroment);
35
+ }
36
+ loadFileSync(filename, currentDirectory, options, enviroment) {
37
+ let resolved;
38
+ try {
39
+ resolved = resolveId(filename);
40
+ } catch (error) {
41
+ _winner_fed_utils.logger.error(error);
42
+ }
43
+ if (!resolved) {
44
+ const error = /* @__PURE__ */ new Error(`[less-plugin-alias]: '${filename}' not found.`);
45
+ _winner_fed_utils.logger.error(error);
46
+ throw error;
47
+ }
48
+ return super.loadFileSync(resolved, currentDirectory, options, enviroment);
49
+ }
50
+ }
51
+ pluginManager.addFileManager(new AliasePlugin());
52
+ }
100
53
  };
54
+ module.exports = LessAliasPlugin;
@@ -1,4 +1,4 @@
1
1
  export interface Alias {
2
- find: string | RegExp;
3
- replacement: string;
2
+ find: string | RegExp;
3
+ replacement: string;
4
4
  }
@@ -1,17 +0,0 @@
1
- var __defProp = Object.defineProperty;
2
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
- var __getOwnPropNames = Object.getOwnPropertyNames;
4
- var __hasOwnProp = Object.prototype.hasOwnProperty;
5
- var __copyProps = (to, from, except, desc) => {
6
- if (from && typeof from === "object" || typeof from === "function") {
7
- for (let key of __getOwnPropNames(from))
8
- if (!__hasOwnProp.call(to, key) && key !== except)
9
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
10
- }
11
- return to;
12
- };
13
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
14
-
15
- // src/plugins/less-plugin-alias/types.ts
16
- var types_exports = {};
17
- module.exports = __toCommonJS(types_exports);
@@ -1,2 +1,2 @@
1
- import { Alias } from './types';
1
+ import { Alias } from "./types.js";
2
2
  export declare function parseAlias(alias: Record<string, string>): Alias[];
@@ -1,60 +1,29 @@
1
- var __defProp = Object.defineProperty;
2
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
- var __getOwnPropNames = Object.getOwnPropertyNames;
4
- var __hasOwnProp = Object.prototype.hasOwnProperty;
5
- var __export = (target, all) => {
6
- for (var name in all)
7
- __defProp(target, name, { get: all[name], enumerable: true });
8
- };
9
- var __copyProps = (to, from, except, desc) => {
10
- if (from && typeof from === "object" || typeof from === "function") {
11
- for (let key of __getOwnPropNames(from))
12
- if (!__hasOwnProp.call(to, key) && key !== except)
13
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
14
- }
15
- return to;
16
- };
17
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
18
-
19
- // src/plugins/less-plugin-alias/utils.ts
20
- var utils_exports = {};
21
- __export(utils_exports, {
22
- parseAlias: () => parseAlias
23
- });
24
- module.exports = __toCommonJS(utils_exports);
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
25
2
  function hoistAlias(alias) {
26
- function getFinalReplacement(oAlias, replacement, index) {
27
- const newAlias = oAlias.slice();
28
- newAlias.splice(index, 1);
29
- for (let i = 0; i < newAlias.length; i++) {
30
- if (newAlias[i].find.test(replacement)) {
31
- replacement = replacement.replace(
32
- newAlias[i].find,
33
- newAlias[i].replacement
34
- );
35
- return getFinalReplacement(newAlias, replacement, i);
36
- }
37
- }
38
- return replacement;
39
- }
40
- alias.forEach((rule, index, alias2) => {
41
- rule.replacement = getFinalReplacement(alias2, rule.replacement, index);
42
- });
43
- return alias;
3
+ function getFinalReplacement(oAlias, replacement, index) {
4
+ const newAlias = oAlias.slice();
5
+ newAlias.splice(index, 1);
6
+ for (let i = 0; i < newAlias.length; i++) if (newAlias[i].find.test(replacement)) {
7
+ replacement = replacement.replace(newAlias[i].find, newAlias[i].replacement);
8
+ return getFinalReplacement(newAlias, replacement, i);
9
+ }
10
+ return replacement;
11
+ }
12
+ alias.forEach((rule, index, alias) => {
13
+ rule.replacement = getFinalReplacement(alias, rule.replacement, index);
14
+ });
15
+ return alias;
44
16
  }
45
17
  function parseAlias(alias) {
46
- const wholeAlias = [
47
- // to support less-loader ~ for local deps, refer: https://github.com/vitejs/vite/issues/2185
48
- { find: /^~/, replacement: "" }
49
- ];
50
- const userAlias = Object.entries(alias).map(([name, target]) => ({
51
- find: new RegExp(`^~?${name.replace(/(?<!\$)$/, "(?=/|$)")}`),
52
- replacement: target
53
- }));
54
- wholeAlias.unshift(...userAlias);
55
- return hoistAlias(wholeAlias);
18
+ const wholeAlias = [{
19
+ find: /^~/,
20
+ replacement: ""
21
+ }];
22
+ const userAlias = Object.entries(alias).map(([name, target]) => ({
23
+ find: new RegExp(`^~?${name.replace(/(?<!\$)$/, "(?=/|$)")}`),
24
+ replacement: target
25
+ }));
26
+ wholeAlias.unshift(...userAlias);
27
+ return hoistAlias(wholeAlias);
56
28
  }
57
- // Annotate the CommonJS export names for ESM import in node:
58
- 0 && (module.exports = {
59
- parseAlias
60
- });
29
+ exports.parseAlias = parseAlias;
@@ -1,9 +1,9 @@
1
- import { Plugin } from '@winner-fed/bundler-utils/compiled/esbuild';
2
- import { IConfig } from '../types';
1
+ import { IConfig } from "../types.js";
2
+ import { Plugin } from "@winner-fed/bundler-utils/compiled/esbuild";
3
3
  export declare const aliasLessImportPath: (filePath: string, alias: Record<string, string>, importer: string) => Promise<string | null>;
4
4
  declare const _default: (options?: Less.Options & {
5
- alias?: Record<string, string>;
6
- inlineStyle?: boolean;
7
- config?: IConfig;
5
+ alias?: Record<string, string>;
6
+ inlineStyle?: boolean;
7
+ config?: IConfig;
8
8
  }) => Plugin;
9
- export default _default;
9
+ export { _default as default };