@utoo/pack 0.0.1-alpha.16 → 0.0.1-alpha.17

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/binding.d.ts CHANGED
@@ -9,12 +9,6 @@ export declare class ExternalObject<T> {
9
9
  [K: symbol]: T
10
10
  }
11
11
  }
12
- export interface TransformOutput {
13
- code: string
14
- map?: string
15
- output?: string
16
- diagnostics: Array<string>
17
- }
18
12
  export interface NapiEndpointConfig {
19
13
 
20
14
  }
@@ -136,7 +130,7 @@ export interface NapiEntrypoints {
136
130
  }
137
131
  export declare function projectWriteAllEntrypointsToDisk(project: { __napiType: "Project" }): Promise<TurbopackResult>
138
132
  export declare function projectEntrypointsSubscribe(project: { __napiType: "Project" }, func: (...args: any[]) => any): { __napiType: "RootTask" }
139
- export declare function projectHmrEvents(project: { __napiType: "Project" }, identifier: string, func: (...args: any[]) => any): { __napiType: "RootTask" }
133
+ export declare function projectHmrEvents(project: { __napiType: "Project" }, identifier: RcStr, func: (...args: any[]) => any): { __napiType: "RootTask" }
140
134
  export interface HmrIdentifiers {
141
135
  identifiers: Array<string>
142
136
  }
@@ -166,16 +160,18 @@ export declare function projectUpdateInfoSubscribe(project: { __napiType: "Proje
166
160
  export interface StackFrame {
167
161
  isServer: boolean
168
162
  isInternal?: boolean
169
- originalFile?: string
170
- file: string
163
+ originalFile?: RcStr
164
+ file: RcStr
165
+ /** 1-indexed, unlike source map tokens */
171
166
  line?: number
167
+ /** 1-indexed, unlike source map tokens */
172
168
  column?: number
173
- methodName?: string
169
+ methodName?: RcStr
174
170
  }
175
171
  export declare function projectTraceSource(project: { __napiType: "Project" }, frame: StackFrame, currentDirectoryFileUrl: string): Promise<StackFrame | null>
176
172
  export declare function projectGetSourceForAsset(project: { __napiType: "Project" }, filePath: string): Promise<string | null>
177
- export declare function projectGetSourceMap(project: { __napiType: "Project" }, filePath: string): Promise<string | null>
178
- export declare function projectGetSourceMapSync(project: { __napiType: "Project" }, filePath: string): string | null
173
+ export declare function projectGetSourceMap(project: { __napiType: "Project" }, filePath: RcStr): Promise<string | null>
174
+ export declare function projectGetSourceMapSync(project: { __napiType: "Project" }, filePath: RcStr): string | null
179
175
  export declare function rootTaskDispose(rootTask: { __napiType: "RootTask" }): void
180
176
  export interface NapiIssue {
181
177
  severity: string
@@ -186,7 +182,7 @@ export interface NapiIssue {
186
182
  detail?: any
187
183
  source?: NapiIssueSource
188
184
  documentationLink: string
189
- subIssues: Array<NapiIssue>
185
+ importTraces: any
190
186
  }
191
187
  export interface NapiIssueSource {
192
188
  source: NapiSource
@@ -94,44 +94,135 @@ compatDefine.pluginName = "DefinePlugin";
94
94
  function compatDefine(maybeWebpackPluginInstance) {
95
95
  return maybeWebpackPluginInstance === null || maybeWebpackPluginInstance === void 0 ? void 0 : maybeWebpackPluginInstance.definitions;
96
96
  }
97
- function compatExternals(webpackExternal) {
97
+ function compatExternals(webpackExternals) {
98
+ if (!webpackExternals) {
99
+ return undefined;
100
+ }
98
101
  let externals = {};
99
- switch (typeof webpackExternal) {
100
- case "string":
101
- externals[webpackExternal] = webpackExternal;
102
+ switch (typeof webpackExternals) {
103
+ case "string": {
104
+ // Single string external: "lodash" -> { "lodash": "lodash" }
105
+ externals[webpackExternals] = webpackExternals;
102
106
  break;
103
- case "object":
104
- if (webpackExternal instanceof RegExp) {
105
- throw "regex enternal not supported yet";
106
- }
107
- else if (Array.isArray(webpackExternal)) {
108
- webpackExternal.forEach((k) => {
109
- switch (typeof k) {
110
- case "string":
111
- externals[k] = k;
112
- break;
113
- default:
114
- throw "non string external item not supported yet";
107
+ }
108
+ case "object": {
109
+ if (Array.isArray(webpackExternals)) {
110
+ // Array of externals: ["lodash", "react"] -> { "lodash": "lodash", "react": "react" }
111
+ externals = webpackExternals.reduce((acc, external) => {
112
+ if (typeof external === "string") {
113
+ acc[external] = external;
115
114
  }
116
- });
115
+ else if (typeof external === "object" && external !== null) {
116
+ Object.assign(acc, compatExternals(external));
117
+ }
118
+ return acc;
119
+ }, {});
120
+ }
121
+ else if (webpackExternals instanceof RegExp) {
122
+ throw "regex external not supported yet";
117
123
  }
118
124
  else {
119
- if ("byLayer" in webpackExternal) {
125
+ if ("byLayer" in webpackExternals) {
120
126
  throw "by layer external item not supported yet";
121
127
  }
122
- Object.entries(webpackExternal).forEach(([k, v]) => {
123
- switch (typeof v) {
124
- case "string":
125
- externals[k] = v;
126
- break;
127
- default:
128
- throw "non string external item not supported yet";
128
+ Object.entries(webpackExternals).forEach(([key, value]) => {
129
+ if (typeof value === "string") {
130
+ // Check if it's a script type with shorthand syntax: "global@https://example.com/script.js"
131
+ if (value.includes("@") &&
132
+ (value.startsWith("script ") || value.includes("://"))) {
133
+ const match = value.match(/^(?:script\s+)?(.+?)@(.+)$/);
134
+ if (match) {
135
+ const [, globalName, scriptUrl] = match;
136
+ // Use utoo-pack string format: "script globalName@url"
137
+ externals[key] = `script ${globalName}@${scriptUrl}`;
138
+ }
139
+ else {
140
+ externals[key] = value;
141
+ }
142
+ }
143
+ else {
144
+ // Simple string mapping: { "react": "React" }
145
+ externals[key] = value;
146
+ }
147
+ }
148
+ else if (Array.isArray(value)) {
149
+ // Array format handling
150
+ if (value.length >= 2) {
151
+ const [first, second] = value;
152
+ // Check if it's a script type array: ["https://example.com/script.js", "GlobalName"]
153
+ if (typeof first === "string" &&
154
+ first.includes("://") &&
155
+ typeof second === "string") {
156
+ // Use utoo-pack object format for script
157
+ externals[key] = {
158
+ root: second,
159
+ type: "script",
160
+ script: first,
161
+ };
162
+ }
163
+ else if (typeof first === "string" &&
164
+ typeof second === "string") {
165
+ // Handle type prefix formats
166
+ if (first.startsWith("commonjs")) {
167
+ externals[key] = `commonjs ${second}`;
168
+ }
169
+ else if (first === "module") {
170
+ externals[key] = `esm ${second}`;
171
+ }
172
+ else if (first === "var" ||
173
+ first === "global" ||
174
+ first === "window") {
175
+ externals[key] = second;
176
+ }
177
+ else if (first === "script") {
178
+ // Script type without URL in array format - treat as regular script prefix
179
+ externals[key] = `script ${second}`;
180
+ }
181
+ else {
182
+ externals[key] = `${first} ${second}`;
183
+ }
184
+ }
185
+ else {
186
+ externals[key] = value[0] || key;
187
+ }
188
+ }
189
+ else {
190
+ externals[key] = value[0] || key;
191
+ }
192
+ }
193
+ else if (typeof value === "object" && value !== null) {
194
+ // Object format: handle complex configurations
195
+ if ("root" in value || "commonjs" in value || "amd" in value) {
196
+ // Standard webpack externals object format
197
+ if (value.commonjs) {
198
+ externals[key] = `commonjs ${value.commonjs}`;
199
+ }
200
+ else if (value.root) {
201
+ externals[key] = value.root;
202
+ }
203
+ else if (value.amd) {
204
+ externals[key] = value.amd;
205
+ }
206
+ else {
207
+ externals[key] = key;
208
+ }
209
+ }
210
+ else {
211
+ // Treat as utoo-pack specific configuration (might already be in correct format)
212
+ externals[key] = value;
213
+ }
214
+ }
215
+ else {
216
+ // Fallback to key name
217
+ externals[key] = key;
129
218
  }
130
219
  });
131
220
  }
132
221
  break;
133
- case "function":
222
+ }
223
+ case "function": {
134
224
  throw "functional external not supported yet";
225
+ }
135
226
  default:
136
227
  break;
137
228
  }
package/esm/binding.d.ts CHANGED
@@ -9,12 +9,6 @@ export declare class ExternalObject<T> {
9
9
  [K: symbol]: T
10
10
  }
11
11
  }
12
- export interface TransformOutput {
13
- code: string
14
- map?: string
15
- output?: string
16
- diagnostics: Array<string>
17
- }
18
12
  export interface NapiEndpointConfig {
19
13
 
20
14
  }
@@ -136,7 +130,7 @@ export interface NapiEntrypoints {
136
130
  }
137
131
  export declare function projectWriteAllEntrypointsToDisk(project: { __napiType: "Project" }): Promise<TurbopackResult>
138
132
  export declare function projectEntrypointsSubscribe(project: { __napiType: "Project" }, func: (...args: any[]) => any): { __napiType: "RootTask" }
139
- export declare function projectHmrEvents(project: { __napiType: "Project" }, identifier: string, func: (...args: any[]) => any): { __napiType: "RootTask" }
133
+ export declare function projectHmrEvents(project: { __napiType: "Project" }, identifier: RcStr, func: (...args: any[]) => any): { __napiType: "RootTask" }
140
134
  export interface HmrIdentifiers {
141
135
  identifiers: Array<string>
142
136
  }
@@ -166,16 +160,18 @@ export declare function projectUpdateInfoSubscribe(project: { __napiType: "Proje
166
160
  export interface StackFrame {
167
161
  isServer: boolean
168
162
  isInternal?: boolean
169
- originalFile?: string
170
- file: string
163
+ originalFile?: RcStr
164
+ file: RcStr
165
+ /** 1-indexed, unlike source map tokens */
171
166
  line?: number
167
+ /** 1-indexed, unlike source map tokens */
172
168
  column?: number
173
- methodName?: string
169
+ methodName?: RcStr
174
170
  }
175
171
  export declare function projectTraceSource(project: { __napiType: "Project" }, frame: StackFrame, currentDirectoryFileUrl: string): Promise<StackFrame | null>
176
172
  export declare function projectGetSourceForAsset(project: { __napiType: "Project" }, filePath: string): Promise<string | null>
177
- export declare function projectGetSourceMap(project: { __napiType: "Project" }, filePath: string): Promise<string | null>
178
- export declare function projectGetSourceMapSync(project: { __napiType: "Project" }, filePath: string): string | null
173
+ export declare function projectGetSourceMap(project: { __napiType: "Project" }, filePath: RcStr): Promise<string | null>
174
+ export declare function projectGetSourceMapSync(project: { __napiType: "Project" }, filePath: RcStr): string | null
179
175
  export declare function rootTaskDispose(rootTask: { __napiType: "RootTask" }): void
180
176
  export interface NapiIssue {
181
177
  severity: string
@@ -186,7 +182,7 @@ export interface NapiIssue {
186
182
  detail?: any
187
183
  source?: NapiIssueSource
188
184
  documentationLink: string
189
- subIssues: Array<NapiIssue>
185
+ importTraces: any
190
186
  }
191
187
  export interface NapiIssueSource {
192
188
  source: NapiSource
@@ -91,44 +91,135 @@ compatDefine.pluginName = "DefinePlugin";
91
91
  function compatDefine(maybeWebpackPluginInstance) {
92
92
  return maybeWebpackPluginInstance === null || maybeWebpackPluginInstance === void 0 ? void 0 : maybeWebpackPluginInstance.definitions;
93
93
  }
94
- function compatExternals(webpackExternal) {
94
+ function compatExternals(webpackExternals) {
95
+ if (!webpackExternals) {
96
+ return undefined;
97
+ }
95
98
  let externals = {};
96
- switch (typeof webpackExternal) {
97
- case "string":
98
- externals[webpackExternal] = webpackExternal;
99
+ switch (typeof webpackExternals) {
100
+ case "string": {
101
+ // Single string external: "lodash" -> { "lodash": "lodash" }
102
+ externals[webpackExternals] = webpackExternals;
99
103
  break;
100
- case "object":
101
- if (webpackExternal instanceof RegExp) {
102
- throw "regex enternal not supported yet";
103
- }
104
- else if (Array.isArray(webpackExternal)) {
105
- webpackExternal.forEach((k) => {
106
- switch (typeof k) {
107
- case "string":
108
- externals[k] = k;
109
- break;
110
- default:
111
- throw "non string external item not supported yet";
104
+ }
105
+ case "object": {
106
+ if (Array.isArray(webpackExternals)) {
107
+ // Array of externals: ["lodash", "react"] -> { "lodash": "lodash", "react": "react" }
108
+ externals = webpackExternals.reduce((acc, external) => {
109
+ if (typeof external === "string") {
110
+ acc[external] = external;
112
111
  }
113
- });
112
+ else if (typeof external === "object" && external !== null) {
113
+ Object.assign(acc, compatExternals(external));
114
+ }
115
+ return acc;
116
+ }, {});
117
+ }
118
+ else if (webpackExternals instanceof RegExp) {
119
+ throw "regex external not supported yet";
114
120
  }
115
121
  else {
116
- if ("byLayer" in webpackExternal) {
122
+ if ("byLayer" in webpackExternals) {
117
123
  throw "by layer external item not supported yet";
118
124
  }
119
- Object.entries(webpackExternal).forEach(([k, v]) => {
120
- switch (typeof v) {
121
- case "string":
122
- externals[k] = v;
123
- break;
124
- default:
125
- throw "non string external item not supported yet";
125
+ Object.entries(webpackExternals).forEach(([key, value]) => {
126
+ if (typeof value === "string") {
127
+ // Check if it's a script type with shorthand syntax: "global@https://example.com/script.js"
128
+ if (value.includes("@") &&
129
+ (value.startsWith("script ") || value.includes("://"))) {
130
+ const match = value.match(/^(?:script\s+)?(.+?)@(.+)$/);
131
+ if (match) {
132
+ const [, globalName, scriptUrl] = match;
133
+ // Use utoo-pack string format: "script globalName@url"
134
+ externals[key] = `script ${globalName}@${scriptUrl}`;
135
+ }
136
+ else {
137
+ externals[key] = value;
138
+ }
139
+ }
140
+ else {
141
+ // Simple string mapping: { "react": "React" }
142
+ externals[key] = value;
143
+ }
144
+ }
145
+ else if (Array.isArray(value)) {
146
+ // Array format handling
147
+ if (value.length >= 2) {
148
+ const [first, second] = value;
149
+ // Check if it's a script type array: ["https://example.com/script.js", "GlobalName"]
150
+ if (typeof first === "string" &&
151
+ first.includes("://") &&
152
+ typeof second === "string") {
153
+ // Use utoo-pack object format for script
154
+ externals[key] = {
155
+ root: second,
156
+ type: "script",
157
+ script: first,
158
+ };
159
+ }
160
+ else if (typeof first === "string" &&
161
+ typeof second === "string") {
162
+ // Handle type prefix formats
163
+ if (first.startsWith("commonjs")) {
164
+ externals[key] = `commonjs ${second}`;
165
+ }
166
+ else if (first === "module") {
167
+ externals[key] = `esm ${second}`;
168
+ }
169
+ else if (first === "var" ||
170
+ first === "global" ||
171
+ first === "window") {
172
+ externals[key] = second;
173
+ }
174
+ else if (first === "script") {
175
+ // Script type without URL in array format - treat as regular script prefix
176
+ externals[key] = `script ${second}`;
177
+ }
178
+ else {
179
+ externals[key] = `${first} ${second}`;
180
+ }
181
+ }
182
+ else {
183
+ externals[key] = value[0] || key;
184
+ }
185
+ }
186
+ else {
187
+ externals[key] = value[0] || key;
188
+ }
189
+ }
190
+ else if (typeof value === "object" && value !== null) {
191
+ // Object format: handle complex configurations
192
+ if ("root" in value || "commonjs" in value || "amd" in value) {
193
+ // Standard webpack externals object format
194
+ if (value.commonjs) {
195
+ externals[key] = `commonjs ${value.commonjs}`;
196
+ }
197
+ else if (value.root) {
198
+ externals[key] = value.root;
199
+ }
200
+ else if (value.amd) {
201
+ externals[key] = value.amd;
202
+ }
203
+ else {
204
+ externals[key] = key;
205
+ }
206
+ }
207
+ else {
208
+ // Treat as utoo-pack specific configuration (might already be in correct format)
209
+ externals[key] = value;
210
+ }
211
+ }
212
+ else {
213
+ // Fallback to key name
214
+ externals[key] = key;
126
215
  }
127
216
  });
128
217
  }
129
218
  break;
130
- case "function":
219
+ }
220
+ case "function": {
131
221
  throw "functional external not supported yet";
222
+ }
132
223
  default:
133
224
  break;
134
225
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@utoo/pack",
3
- "version": "0.0.1-alpha.16",
3
+ "version": "0.0.1-alpha.17",
4
4
  "main": "cjs/index.js",
5
5
  "module": "esm/index.js",
6
6
  "exports": {
@@ -81,12 +81,12 @@
81
81
  },
82
82
  "repository": "git@github.com:umijs/mako.git",
83
83
  "optionalDependencies": {
84
- "@utoo/pack-darwin-arm64": "0.0.1-alpha.16",
85
- "@utoo/pack-darwin-x64": "0.0.1-alpha.16",
86
- "@utoo/pack-linux-arm64-gnu": "0.0.1-alpha.16",
87
- "@utoo/pack-linux-arm64-musl": "0.0.1-alpha.16",
88
- "@utoo/pack-linux-x64-gnu": "0.0.1-alpha.16",
89
- "@utoo/pack-linux-x64-musl": "0.0.1-alpha.16",
90
- "@utoo/pack-win32-x64-msvc": "0.0.1-alpha.16"
84
+ "@utoo/pack-darwin-arm64": "0.0.1-alpha.17",
85
+ "@utoo/pack-darwin-x64": "0.0.1-alpha.17",
86
+ "@utoo/pack-linux-arm64-gnu": "0.0.1-alpha.17",
87
+ "@utoo/pack-linux-arm64-musl": "0.0.1-alpha.17",
88
+ "@utoo/pack-linux-x64-gnu": "0.0.1-alpha.17",
89
+ "@utoo/pack-linux-x64-musl": "0.0.1-alpha.17",
90
+ "@utoo/pack-win32-x64-msvc": "0.0.1-alpha.17"
91
91
  }
92
92
  }