@utoo/pack 1.1.2-alpha.5 → 1.1.2

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/cjs/types.d.ts CHANGED
@@ -98,6 +98,21 @@ export interface ExternalAdvanced {
98
98
  script?: string;
99
99
  }
100
100
  export type ExternalConfig = string | ExternalAdvanced;
101
+ /**
102
+ * Provider configuration for automatic module imports.
103
+ * Similar to webpack's ProvidePlugin.
104
+ *
105
+ * @example
106
+ * ```ts
107
+ * provider: {
108
+ * // Provides `$` as `import $ from 'jquery'`
109
+ * $: 'jquery',
110
+ * // Provides `Buffer` as `import { Buffer } from 'buffer'`
111
+ * Buffer: ['buffer', 'Buffer'],
112
+ * }
113
+ * ```
114
+ */
115
+ export type ProviderConfig = Record<string, string | [string, string]>;
101
116
  export interface ConfigComplete {
102
117
  entry: EntryOptions[];
103
118
  mode?: "production" | "development";
@@ -119,6 +134,7 @@ export interface ConfigComplete {
119
134
  target?: string;
120
135
  sourceMaps?: boolean;
121
136
  define?: Record<string, string>;
137
+ provider?: ProviderConfig;
122
138
  optimization?: {
123
139
  moduleIds?: "named" | "deterministic";
124
140
  minify?: boolean;
@@ -29,6 +29,7 @@ function compatOptionsFromWebpack(webpackConfig, projectPath, rootPath) {
29
29
  sourceMaps: compatSourceMaps(devtool),
30
30
  optimization: compatOptimization(optimization),
31
31
  define: compatFromWebpackPlugin(plugins, compatDefine),
32
+ provider: compatFromWebpackPlugin(plugins, compatProvider),
32
33
  stats: compatStats(stats),
33
34
  },
34
35
  buildId: webpackConfig.name,
@@ -129,6 +130,31 @@ function compatDefine(maybeWebpackPluginInstance) {
129
130
  }
130
131
  return processedDefinitions;
131
132
  }
133
+ compatProvider.pluginName = "ProvidePlugin";
134
+ function compatProvider(maybeWebpackPluginInstance) {
135
+ const definitions = maybeWebpackPluginInstance === null || maybeWebpackPluginInstance === void 0 ? void 0 : maybeWebpackPluginInstance.definitions;
136
+ if (!definitions || typeof definitions !== "object") {
137
+ return undefined;
138
+ }
139
+ const provider = {};
140
+ for (const [key, value] of Object.entries(definitions)) {
141
+ if (typeof value === "string") {
142
+ // Simple module import: { $: 'jquery' }
143
+ provider[key] = value;
144
+ }
145
+ else if (Array.isArray(value)) {
146
+ if (value.length === 1) {
147
+ // e.g. { process: ['process/browser'] } for default import
148
+ provider[key] = value[0];
149
+ }
150
+ else if (value.length >= 2) {
151
+ // Named export import: { Buffer: ['buffer', 'Buffer'] }
152
+ provider[key] = [value[0], value[1]];
153
+ }
154
+ }
155
+ }
156
+ return Object.keys(provider).length > 0 ? provider : undefined;
157
+ }
132
158
  function compatExternals(webpackExternals) {
133
159
  if (!webpackExternals) {
134
160
  return undefined;
package/esm/types.d.ts CHANGED
@@ -98,6 +98,21 @@ export interface ExternalAdvanced {
98
98
  script?: string;
99
99
  }
100
100
  export type ExternalConfig = string | ExternalAdvanced;
101
+ /**
102
+ * Provider configuration for automatic module imports.
103
+ * Similar to webpack's ProvidePlugin.
104
+ *
105
+ * @example
106
+ * ```ts
107
+ * provider: {
108
+ * // Provides `$` as `import $ from 'jquery'`
109
+ * $: 'jquery',
110
+ * // Provides `Buffer` as `import { Buffer } from 'buffer'`
111
+ * Buffer: ['buffer', 'Buffer'],
112
+ * }
113
+ * ```
114
+ */
115
+ export type ProviderConfig = Record<string, string | [string, string]>;
101
116
  export interface ConfigComplete {
102
117
  entry: EntryOptions[];
103
118
  mode?: "production" | "development";
@@ -119,6 +134,7 @@ export interface ConfigComplete {
119
134
  target?: string;
120
135
  sourceMaps?: boolean;
121
136
  define?: Record<string, string>;
137
+ provider?: ProviderConfig;
122
138
  optimization?: {
123
139
  moduleIds?: "named" | "deterministic";
124
140
  minify?: boolean;
@@ -22,6 +22,7 @@ export function compatOptionsFromWebpack(webpackConfig, projectPath, rootPath) {
22
22
  sourceMaps: compatSourceMaps(devtool),
23
23
  optimization: compatOptimization(optimization),
24
24
  define: compatFromWebpackPlugin(plugins, compatDefine),
25
+ provider: compatFromWebpackPlugin(plugins, compatProvider),
25
26
  stats: compatStats(stats),
26
27
  },
27
28
  buildId: webpackConfig.name,
@@ -122,6 +123,31 @@ function compatDefine(maybeWebpackPluginInstance) {
122
123
  }
123
124
  return processedDefinitions;
124
125
  }
126
+ compatProvider.pluginName = "ProvidePlugin";
127
+ function compatProvider(maybeWebpackPluginInstance) {
128
+ const definitions = maybeWebpackPluginInstance === null || maybeWebpackPluginInstance === void 0 ? void 0 : maybeWebpackPluginInstance.definitions;
129
+ if (!definitions || typeof definitions !== "object") {
130
+ return undefined;
131
+ }
132
+ const provider = {};
133
+ for (const [key, value] of Object.entries(definitions)) {
134
+ if (typeof value === "string") {
135
+ // Simple module import: { $: 'jquery' }
136
+ provider[key] = value;
137
+ }
138
+ else if (Array.isArray(value)) {
139
+ if (value.length === 1) {
140
+ // e.g. { process: ['process/browser'] } for default import
141
+ provider[key] = value[0];
142
+ }
143
+ else if (value.length >= 2) {
144
+ // Named export import: { Buffer: ['buffer', 'Buffer'] }
145
+ provider[key] = [value[0], value[1]];
146
+ }
147
+ }
148
+ }
149
+ return Object.keys(provider).length > 0 ? provider : undefined;
150
+ }
125
151
  function compatExternals(webpackExternals) {
126
152
  if (!webpackExternals) {
127
153
  return undefined;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@utoo/pack",
3
- "version": "1.1.2-alpha.5",
3
+ "version": "1.1.2",
4
4
  "main": "cjs/index.js",
5
5
  "module": "esm/index.js",
6
6
  "types": "esm/index.d.ts",
@@ -89,12 +89,12 @@
89
89
  },
90
90
  "repository": "git@github.com:utooland/utoo.git",
91
91
  "optionalDependencies": {
92
- "@utoo/pack-darwin-arm64": "1.1.2-alpha.5",
93
- "@utoo/pack-darwin-x64": "1.1.2-alpha.5",
94
- "@utoo/pack-linux-arm64-gnu": "1.1.2-alpha.5",
95
- "@utoo/pack-linux-arm64-musl": "1.1.2-alpha.5",
96
- "@utoo/pack-linux-x64-gnu": "1.1.2-alpha.5",
97
- "@utoo/pack-linux-x64-musl": "1.1.2-alpha.5",
98
- "@utoo/pack-win32-x64-msvc": "1.1.2-alpha.5"
92
+ "@utoo/pack-darwin-arm64": "1.1.2",
93
+ "@utoo/pack-darwin-x64": "1.1.2",
94
+ "@utoo/pack-linux-arm64-gnu": "1.1.2",
95
+ "@utoo/pack-linux-arm64-musl": "1.1.2",
96
+ "@utoo/pack-linux-x64-gnu": "1.1.2",
97
+ "@utoo/pack-linux-x64-musl": "1.1.2",
98
+ "@utoo/pack-win32-x64-msvc": "1.1.2"
99
99
  }
100
100
  }