@utoo/pack-shared 0.0.7 → 1.1.8-rc.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/README.md +19 -0
- package/cjs/config.d.ts +227 -0
- package/cjs/config.js +2 -0
- package/cjs/index.d.ts +3 -0
- package/cjs/index.js +17 -0
- package/cjs/utils.d.ts +20 -0
- package/cjs/utils.js +134 -0
- package/cjs/webpackCompat.d.ts +6 -0
- package/cjs/webpackCompat.js +413 -0
- package/esm/config.d.ts +227 -0
- package/esm/config.js +1 -0
- package/esm/index.d.ts +3 -0
- package/esm/index.js +6 -10
- package/esm/issue.js +8 -12
- package/esm/magicIdentifier.js +2 -6
- package/esm/styledString.js +8 -11
- package/esm/utils.d.ts +20 -0
- package/esm/utils.js +125 -0
- package/esm/webpackCompat.d.ts +6 -0
- package/esm/webpackCompat.js +410 -0
- package/package.json +11 -8
package/README.md
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
# @utoo/pack-shared
|
|
2
|
+
|
|
3
|
+
Shared utilities and types for the Utoo toolchain.
|
|
4
|
+
|
|
5
|
+
## 📦 Features
|
|
6
|
+
|
|
7
|
+
- ⚠️ **Issue Reporting**: Standardized issue and error reporting utilities.
|
|
8
|
+
- 🆔 **Magic Identifiers**: Utilities for handling internal identifiers.
|
|
9
|
+
- 🎨 **Styled Strings**: Terminal string styling helpers.
|
|
10
|
+
|
|
11
|
+
## 📦 Installation
|
|
12
|
+
|
|
13
|
+
```bash
|
|
14
|
+
npm install @utoo/pack-shared
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
## 📄 License
|
|
18
|
+
|
|
19
|
+
[MIT](./LICENSE)
|
package/cjs/config.d.ts
ADDED
|
@@ -0,0 +1,227 @@
|
|
|
1
|
+
export interface EntryOptions {
|
|
2
|
+
name?: string;
|
|
3
|
+
import: string;
|
|
4
|
+
library?: LibraryOptions;
|
|
5
|
+
/**
|
|
6
|
+
* Configuration for generating an HTML file for this entry point.
|
|
7
|
+
* When specified, an HTML file will be generated with the entry's assets injected.
|
|
8
|
+
*
|
|
9
|
+
* Similar to https://github.com/jantimon/html-webpack-plugin#options
|
|
10
|
+
*/
|
|
11
|
+
html?: HtmlConfig;
|
|
12
|
+
}
|
|
13
|
+
export interface LibraryOptions {
|
|
14
|
+
name?: string;
|
|
15
|
+
export?: Array<string>;
|
|
16
|
+
}
|
|
17
|
+
export interface DefineEnv {
|
|
18
|
+
client: RustifiedEnv;
|
|
19
|
+
edge: RustifiedEnv;
|
|
20
|
+
nodejs: RustifiedEnv;
|
|
21
|
+
}
|
|
22
|
+
export type RustifiedEnv = {
|
|
23
|
+
name: string;
|
|
24
|
+
value: string;
|
|
25
|
+
}[];
|
|
26
|
+
export interface ExperimentalConfig {
|
|
27
|
+
}
|
|
28
|
+
export type TurbopackRuleConfigItem = TurbopackRuleConfigItemOptions | {
|
|
29
|
+
[condition: string]: TurbopackRuleConfigItem;
|
|
30
|
+
} | false;
|
|
31
|
+
/**
|
|
32
|
+
* @deprecated Use `TurbopackRuleConfigItem` instead.
|
|
33
|
+
*/
|
|
34
|
+
export type TurbopackLoaderItem = string | {
|
|
35
|
+
loader: string;
|
|
36
|
+
options: Record<string, JSONValue>;
|
|
37
|
+
};
|
|
38
|
+
export type TurbopackRuleConfigItemOrShortcut = TurbopackLoaderItem[] | TurbopackRuleConfigItem;
|
|
39
|
+
export type TurbopackRuleConfigItemOptions = {
|
|
40
|
+
loaders: TurbopackLoaderItem[];
|
|
41
|
+
as?: string;
|
|
42
|
+
};
|
|
43
|
+
export type TurbopackRuleCondition = {
|
|
44
|
+
path: string | RegExp;
|
|
45
|
+
};
|
|
46
|
+
export interface ModuleOptions {
|
|
47
|
+
rules?: Record<string, TurbopackRuleConfigItem>;
|
|
48
|
+
}
|
|
49
|
+
export interface ResolveOptions {
|
|
50
|
+
alias?: Record<string, string | string[] | Record<string, string | string[]>>;
|
|
51
|
+
extensions?: string[];
|
|
52
|
+
}
|
|
53
|
+
export type ExternalType = "script" | "commonjs" | "esm" | "global";
|
|
54
|
+
export interface ExternalAdvanced {
|
|
55
|
+
root: string;
|
|
56
|
+
type?: ExternalType;
|
|
57
|
+
script?: string;
|
|
58
|
+
}
|
|
59
|
+
export type ExternalConfig = string | ExternalAdvanced;
|
|
60
|
+
/**
|
|
61
|
+
* Provider configuration for automatic module imports.
|
|
62
|
+
* Similar to webpack's ProvidePlugin.
|
|
63
|
+
*
|
|
64
|
+
* @example
|
|
65
|
+
* ```ts
|
|
66
|
+
* provider: {
|
|
67
|
+
* // Provides `$` as `import $ from 'jquery'`
|
|
68
|
+
* $: 'jquery',
|
|
69
|
+
* // Provides `Buffer` as `import { Buffer } from 'buffer'`
|
|
70
|
+
* Buffer: ['buffer', 'Buffer'],
|
|
71
|
+
* }
|
|
72
|
+
* ```
|
|
73
|
+
*/
|
|
74
|
+
export type ProviderConfig = Record<string, string | [string, string]>;
|
|
75
|
+
export interface ConfigComplete {
|
|
76
|
+
entry: EntryOptions[];
|
|
77
|
+
mode?: "production" | "development";
|
|
78
|
+
module?: ModuleOptions;
|
|
79
|
+
resolve?: ResolveOptions;
|
|
80
|
+
externals?: Record<string, ExternalConfig>;
|
|
81
|
+
output?: {
|
|
82
|
+
path?: string;
|
|
83
|
+
type?: "standalone" | "export";
|
|
84
|
+
filename?: string;
|
|
85
|
+
chunkFilename?: string;
|
|
86
|
+
clean?: boolean;
|
|
87
|
+
copy?: Array<{
|
|
88
|
+
from: string;
|
|
89
|
+
to?: string;
|
|
90
|
+
} | string>;
|
|
91
|
+
publicPath?: string;
|
|
92
|
+
};
|
|
93
|
+
target?: string;
|
|
94
|
+
sourceMaps?: boolean;
|
|
95
|
+
define?: Record<string, string>;
|
|
96
|
+
provider?: ProviderConfig;
|
|
97
|
+
optimization?: {
|
|
98
|
+
moduleIds?: "named" | "deterministic";
|
|
99
|
+
minify?: boolean;
|
|
100
|
+
treeShaking?: boolean;
|
|
101
|
+
splitChunks?: Record<"js" | "css", {
|
|
102
|
+
minChunkSize?: number;
|
|
103
|
+
maxChunkCountPerGroup?: number;
|
|
104
|
+
maxMergeChunkSize?: number;
|
|
105
|
+
}>;
|
|
106
|
+
modularizeImports?: Record<string, {
|
|
107
|
+
transform: string | Record<string, string>;
|
|
108
|
+
preventFullImport?: boolean;
|
|
109
|
+
skipDefaultConversion?: boolean;
|
|
110
|
+
handleDefaultImport?: boolean;
|
|
111
|
+
handleNamespaceImport?: boolean;
|
|
112
|
+
style?: string;
|
|
113
|
+
}>;
|
|
114
|
+
packageImports?: string[];
|
|
115
|
+
transpilePackages?: string[];
|
|
116
|
+
removeConsole?: boolean | {
|
|
117
|
+
exclude?: string[];
|
|
118
|
+
};
|
|
119
|
+
concatenateModules?: boolean;
|
|
120
|
+
removeUnusedExports?: boolean;
|
|
121
|
+
nestedAsyncChunking?: boolean;
|
|
122
|
+
wasmAsAsset?: boolean;
|
|
123
|
+
};
|
|
124
|
+
styles?: {
|
|
125
|
+
less?: {
|
|
126
|
+
implementation?: string;
|
|
127
|
+
[key: string]: any;
|
|
128
|
+
};
|
|
129
|
+
sass?: {
|
|
130
|
+
implementation?: string;
|
|
131
|
+
[key: string]: any;
|
|
132
|
+
};
|
|
133
|
+
inlineCss?: {
|
|
134
|
+
insert?: string;
|
|
135
|
+
injectType?: string;
|
|
136
|
+
};
|
|
137
|
+
styledJsx?: boolean | {
|
|
138
|
+
useLightningcss?: boolean;
|
|
139
|
+
};
|
|
140
|
+
styledComponents?: boolean | StyledComponentsConfig;
|
|
141
|
+
emotion?: boolean | EmotionConfig;
|
|
142
|
+
};
|
|
143
|
+
images?: {
|
|
144
|
+
inlineLimit?: number;
|
|
145
|
+
};
|
|
146
|
+
stats?: boolean;
|
|
147
|
+
persistentCaching?: boolean;
|
|
148
|
+
nodePolyfill?: boolean;
|
|
149
|
+
devServer?: {
|
|
150
|
+
hot: boolean;
|
|
151
|
+
};
|
|
152
|
+
cacheHandler?: string;
|
|
153
|
+
experimental?: ExperimentalConfig;
|
|
154
|
+
}
|
|
155
|
+
export interface HtmlConfig {
|
|
156
|
+
template?: string;
|
|
157
|
+
templateContent?: string;
|
|
158
|
+
filename?: string;
|
|
159
|
+
title?: string;
|
|
160
|
+
inject?: boolean | "body" | "head";
|
|
161
|
+
scriptLoading?: "blocking" | "defer" | "module";
|
|
162
|
+
meta?: Record<string, string | {
|
|
163
|
+
[key: string]: string;
|
|
164
|
+
}>;
|
|
165
|
+
}
|
|
166
|
+
export interface StyledComponentsConfig {
|
|
167
|
+
/**
|
|
168
|
+
* Enabled by default in development, disabled in production to reduce file size,
|
|
169
|
+
* setting this will override the default for all environments.
|
|
170
|
+
*/
|
|
171
|
+
displayName?: boolean;
|
|
172
|
+
topLevelImportPaths?: string[];
|
|
173
|
+
ssr?: boolean;
|
|
174
|
+
fileName?: boolean;
|
|
175
|
+
meaninglessFileNames?: string[];
|
|
176
|
+
minify?: boolean;
|
|
177
|
+
transpileTemplateLiterals?: boolean;
|
|
178
|
+
namespace?: string;
|
|
179
|
+
pure?: boolean;
|
|
180
|
+
cssProp?: boolean;
|
|
181
|
+
}
|
|
182
|
+
export interface EmotionConfig {
|
|
183
|
+
sourceMap?: boolean;
|
|
184
|
+
autoLabel?: "dev-only" | "always" | "never";
|
|
185
|
+
labelFormat?: string;
|
|
186
|
+
importMap?: {
|
|
187
|
+
[importName: string]: {
|
|
188
|
+
[exportName: string]: {
|
|
189
|
+
canonicalImport?: [string, string];
|
|
190
|
+
styledBaseImport?: [string, string];
|
|
191
|
+
};
|
|
192
|
+
};
|
|
193
|
+
};
|
|
194
|
+
}
|
|
195
|
+
export type JSONValue = string | number | boolean | JSONValue[] | {
|
|
196
|
+
[k: string]: JSONValue;
|
|
197
|
+
};
|
|
198
|
+
export interface BundleOptions {
|
|
199
|
+
/**
|
|
200
|
+
* The utoo pack configs.
|
|
201
|
+
*/
|
|
202
|
+
config: ConfigComplete;
|
|
203
|
+
/**
|
|
204
|
+
* A map of environment variables to use when compiling code.
|
|
205
|
+
*/
|
|
206
|
+
processEnv?: Record<string, string>;
|
|
207
|
+
defineEnv?: DefineEnv;
|
|
208
|
+
/**
|
|
209
|
+
* Whether to watch the filesystem for file changes.
|
|
210
|
+
*/
|
|
211
|
+
watch?: {
|
|
212
|
+
enable: boolean;
|
|
213
|
+
pollIntervalMs?: number;
|
|
214
|
+
};
|
|
215
|
+
/**
|
|
216
|
+
* The mode of utoopack.
|
|
217
|
+
*/
|
|
218
|
+
dev?: boolean;
|
|
219
|
+
/**
|
|
220
|
+
* The build id.
|
|
221
|
+
*/
|
|
222
|
+
buildId?: string;
|
|
223
|
+
/**
|
|
224
|
+
* Absolute path for `@utoo/pack`.
|
|
225
|
+
*/
|
|
226
|
+
packPath?: string;
|
|
227
|
+
}
|
package/cjs/config.js
ADDED
package/cjs/index.d.ts
CHANGED
|
@@ -1,3 +1,6 @@
|
|
|
1
|
+
export * from "./config";
|
|
1
2
|
export { formatIssue, handleIssues, Issue } from "./issue";
|
|
2
3
|
export { decodeMagicIdentifier } from "./magicIdentifier";
|
|
3
4
|
export { renderStyledStringToErrorAnsi } from "./styledString";
|
|
5
|
+
export * from "./utils";
|
|
6
|
+
export * from "./webpackCompat";
|
package/cjs/index.js
CHANGED
|
@@ -1,6 +1,21 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
2
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
17
|
exports.renderStyledStringToErrorAnsi = exports.decodeMagicIdentifier = exports.handleIssues = exports.formatIssue = void 0;
|
|
18
|
+
__exportStar(require("./config"), exports);
|
|
4
19
|
var issue_1 = require("./issue");
|
|
5
20
|
Object.defineProperty(exports, "formatIssue", { enumerable: true, get: function () { return issue_1.formatIssue; } });
|
|
6
21
|
Object.defineProperty(exports, "handleIssues", { enumerable: true, get: function () { return issue_1.handleIssues; } });
|
|
@@ -8,3 +23,5 @@ var magicIdentifier_1 = require("./magicIdentifier");
|
|
|
8
23
|
Object.defineProperty(exports, "decodeMagicIdentifier", { enumerable: true, get: function () { return magicIdentifier_1.decodeMagicIdentifier; } });
|
|
9
24
|
var styledString_1 = require("./styledString");
|
|
10
25
|
Object.defineProperty(exports, "renderStyledStringToErrorAnsi", { enumerable: true, get: function () { return styledString_1.renderStyledStringToErrorAnsi; } });
|
|
26
|
+
__exportStar(require("./utils"), exports);
|
|
27
|
+
__exportStar(require("./webpackCompat"), exports);
|
package/cjs/utils.d.ts
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { ConfigComplete, DefineEnv, RustifiedEnv } from "./config";
|
|
2
|
+
import { Issue } from "./issue";
|
|
3
|
+
export declare class ModuleBuildError extends Error {
|
|
4
|
+
name: string;
|
|
5
|
+
}
|
|
6
|
+
export interface ResultWithIssues {
|
|
7
|
+
issues: Issue[];
|
|
8
|
+
}
|
|
9
|
+
export declare function processIssues(result: ResultWithIssues, throwIssue: boolean, logErrors: boolean): void;
|
|
10
|
+
export declare function isWellKnownError(issue: Issue): boolean;
|
|
11
|
+
export declare function rustifyEnv(env: Record<string, string>): RustifiedEnv;
|
|
12
|
+
interface DefineEnvOptions {
|
|
13
|
+
config: ConfigComplete;
|
|
14
|
+
dev: boolean;
|
|
15
|
+
optionDefineEnv?: DefineEnv;
|
|
16
|
+
}
|
|
17
|
+
export declare function createDefineEnv(options: DefineEnvOptions): DefineEnv;
|
|
18
|
+
type AnyFunc<T> = (this: T, ...args: any) => any;
|
|
19
|
+
export declare function debounce<T, F extends AnyFunc<T>>(fn: F, ms: number, maxWait?: number): (this: T, ...passedArgs: Parameters<F>) => void;
|
|
20
|
+
export {};
|
package/cjs/utils.js
ADDED
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ModuleBuildError = void 0;
|
|
4
|
+
exports.processIssues = processIssues;
|
|
5
|
+
exports.isWellKnownError = isWellKnownError;
|
|
6
|
+
exports.rustifyEnv = rustifyEnv;
|
|
7
|
+
exports.createDefineEnv = createDefineEnv;
|
|
8
|
+
exports.debounce = debounce;
|
|
9
|
+
const issue_1 = require("./issue");
|
|
10
|
+
const styledString_1 = require("./styledString");
|
|
11
|
+
class ModuleBuildError extends Error {
|
|
12
|
+
constructor() {
|
|
13
|
+
super(...arguments);
|
|
14
|
+
this.name = "ModuleBuildError";
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
exports.ModuleBuildError = ModuleBuildError;
|
|
18
|
+
function processIssues(result, throwIssue, logErrors) {
|
|
19
|
+
const relevantIssues = new Set();
|
|
20
|
+
for (const issue of result.issues) {
|
|
21
|
+
if (issue.severity !== "error" &&
|
|
22
|
+
issue.severity !== "fatal" &&
|
|
23
|
+
issue.severity !== "warning")
|
|
24
|
+
continue;
|
|
25
|
+
if (issue.severity !== "warning") {
|
|
26
|
+
if (throwIssue) {
|
|
27
|
+
const formatted = (0, issue_1.formatIssue)(issue);
|
|
28
|
+
relevantIssues.add(formatted);
|
|
29
|
+
}
|
|
30
|
+
// if we throw the issue it will most likely get handed and logged elsewhere
|
|
31
|
+
else if (logErrors && isWellKnownError(issue)) {
|
|
32
|
+
const formatted = (0, issue_1.formatIssue)(issue);
|
|
33
|
+
console.error(formatted);
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
if (relevantIssues.size && throwIssue) {
|
|
38
|
+
throw new ModuleBuildError([...relevantIssues].join("\n\n"));
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
function isWellKnownError(issue) {
|
|
42
|
+
const { title } = issue;
|
|
43
|
+
const formattedTitle = (0, styledString_1.renderStyledStringToErrorAnsi)(title);
|
|
44
|
+
// TODO: add more well known errors
|
|
45
|
+
if (formattedTitle.includes("Module not found") ||
|
|
46
|
+
formattedTitle.includes("Unknown module type")) {
|
|
47
|
+
return true;
|
|
48
|
+
}
|
|
49
|
+
return false;
|
|
50
|
+
}
|
|
51
|
+
function rustifyEnv(env) {
|
|
52
|
+
return Object.entries(env)
|
|
53
|
+
.filter(([_, value]) => value != null)
|
|
54
|
+
.map(([name, value]) => ({
|
|
55
|
+
name,
|
|
56
|
+
value,
|
|
57
|
+
}));
|
|
58
|
+
}
|
|
59
|
+
function createDefineEnv(options) {
|
|
60
|
+
var _a;
|
|
61
|
+
let defineEnv = (_a = options.optionDefineEnv) !== null && _a !== void 0 ? _a : {
|
|
62
|
+
client: [],
|
|
63
|
+
edge: [],
|
|
64
|
+
nodejs: [],
|
|
65
|
+
};
|
|
66
|
+
function getDefineEnv() {
|
|
67
|
+
var _a;
|
|
68
|
+
const envs = {
|
|
69
|
+
"process.env.NODE_ENV": options.dev ? "development" : "production",
|
|
70
|
+
};
|
|
71
|
+
const userDefines = (_a = options.config.define) !== null && _a !== void 0 ? _a : {};
|
|
72
|
+
for (const key in userDefines) {
|
|
73
|
+
envs[key] = userDefines[key];
|
|
74
|
+
}
|
|
75
|
+
// serialize
|
|
76
|
+
const defineEnvStringified = {};
|
|
77
|
+
for (const key in defineEnv) {
|
|
78
|
+
const value = envs[key];
|
|
79
|
+
defineEnvStringified[key] = JSON.stringify(value);
|
|
80
|
+
}
|
|
81
|
+
return defineEnvStringified;
|
|
82
|
+
}
|
|
83
|
+
// TODO: future define envs need to extends for more compiler like server or edge.
|
|
84
|
+
for (const variant of Object.keys(defineEnv)) {
|
|
85
|
+
defineEnv[variant] = rustifyEnv(getDefineEnv());
|
|
86
|
+
}
|
|
87
|
+
return defineEnv;
|
|
88
|
+
}
|
|
89
|
+
function debounce(fn, ms, maxWait = Infinity) {
|
|
90
|
+
let timeoutId;
|
|
91
|
+
// The time the debouncing function was first called during this debounce queue.
|
|
92
|
+
let startTime = 0;
|
|
93
|
+
// The time the debouncing function was last called.
|
|
94
|
+
let lastCall = 0;
|
|
95
|
+
// The arguments and this context of the last call to the debouncing function.
|
|
96
|
+
let args, context;
|
|
97
|
+
// A helper used to that either invokes the debounced function, or
|
|
98
|
+
// reschedules the timer if a more recent call was made.
|
|
99
|
+
function run() {
|
|
100
|
+
const now = Date.now();
|
|
101
|
+
const diff = lastCall + ms - now;
|
|
102
|
+
// If the diff is non-positive, then we've waited at least `ms`
|
|
103
|
+
// milliseconds since the last call. Or if we've waited for longer than the
|
|
104
|
+
// max wait time, we must call the debounced function.
|
|
105
|
+
if (diff <= 0 || startTime + maxWait >= now) {
|
|
106
|
+
// It's important to clear the timeout id before invoking the debounced
|
|
107
|
+
// function, in case the function calls the debouncing function again.
|
|
108
|
+
timeoutId = undefined;
|
|
109
|
+
fn.apply(context, args);
|
|
110
|
+
}
|
|
111
|
+
else {
|
|
112
|
+
// Else, a new call was made after the original timer was scheduled. We
|
|
113
|
+
// didn't clear the timeout (doing so is very slow), so now we need to
|
|
114
|
+
// reschedule the timer for the time difference.
|
|
115
|
+
timeoutId = setTimeout(run, diff);
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
return function (...passedArgs) {
|
|
119
|
+
// The arguments and this context of the most recent call are saved so the
|
|
120
|
+
// debounced function can be invoked with them later.
|
|
121
|
+
args = passedArgs;
|
|
122
|
+
context = this;
|
|
123
|
+
// Instead of constantly clearing and scheduling a timer, we record the
|
|
124
|
+
// time of the last call. If a second call comes in before the timer fires,
|
|
125
|
+
// then we'll reschedule in the run function. Doing this is considerably
|
|
126
|
+
// faster.
|
|
127
|
+
lastCall = Date.now();
|
|
128
|
+
// Only schedule a new timer if we're not currently waiting.
|
|
129
|
+
if (timeoutId === undefined) {
|
|
130
|
+
startTime = lastCall;
|
|
131
|
+
timeoutId = setTimeout(run, ms);
|
|
132
|
+
}
|
|
133
|
+
};
|
|
134
|
+
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type webpack from "webpack";
|
|
2
|
+
import { BundleOptions } from "./config";
|
|
3
|
+
export type WebpackConfig = Partial<Pick<webpack.Configuration, "name" | "entry" | "mode" | "module" | "resolve" | "externals" | "output" | "target" | "devtool" | "optimization" | "plugins" | "stats">> & {
|
|
4
|
+
webpackMode: true;
|
|
5
|
+
};
|
|
6
|
+
export declare function compatOptionsFromWebpack(webpackConfig: WebpackConfig): BundleOptions;
|