Skip to content

Commit 5901006

Browse files
feat: drop cjs wrapper (#654)
1 parent d6a6cdb commit 5901006

File tree

7 files changed

+148
-132
lines changed

7 files changed

+148
-132
lines changed

package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,14 @@
1111
"type": "opencollective",
1212
"url": "https://opencollective.com/webpack"
1313
},
14-
"main": "dist/cjs.js",
15-
"types": "types/cjs.d.ts",
14+
"main": "dist/index.js",
15+
"types": "types/index.d.ts",
1616
"engines": {
1717
"node": ">= 12.20.0"
1818
},
1919
"scripts": {
2020
"start": "npm run build -- -w",
21-
"clean": "del-cli dist",
21+
"clean": "del-cli dist types",
2222
"prebuild": "npm run clean",
2323
"build:types": "tsc --declaration --emitDeclarationOnly --outDir types --rootDir src && prettier \"types/**/*.ts\" --write",
2424
"build:code": "cross-env NODE_ENV=production babel src -d dist --copy-files",

src/cjs.js

Lines changed: 0 additions & 3 deletions
This file was deleted.

src/index.js

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
1-
import path from "path";
1+
const path = require("path");
22

3-
import { validate } from "schema-utils";
4-
import serialize from "serialize-javascript";
5-
import normalizePath from "normalize-path";
6-
import globParent from "glob-parent";
7-
import fastGlob from "fast-glob";
3+
const { validate } = require("schema-utils");
4+
const serialize = require("serialize-javascript");
5+
const normalizePath = require("normalize-path");
6+
const globParent = require("glob-parent");
7+
const fastGlob = require("fast-glob");
88

99
// @ts-ignore
10-
import { version } from "../package.json";
10+
const { version } = require("../package.json");
1111

12-
import schema from "./options.json";
13-
import { readFile, stat, throttleAll } from "./utils";
12+
const schema = require("./options.json");
13+
const { readFile, stat, throttleAll } = require("./utils");
1414

1515
const template = /\[\\*([\w:]+)\\*\]/i;
1616

@@ -1096,4 +1096,4 @@ class CopyPlugin {
10961096
}
10971097
}
10981098

1099-
export default CopyPlugin;
1099+
module.exports = CopyPlugin;

src/utils.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,4 +119,4 @@ function throttleAll(limit, tasks) {
119119
});
120120
}
121121

122-
export { stat, readFile, throttleAll };
122+
module.exports = { stat, readFile, throttleAll };

test/cjs.test.js

Lines changed: 0 additions & 8 deletions
This file was deleted.

types/cjs.d.ts

Lines changed: 0 additions & 3 deletions
This file was deleted.

types/index.d.ts

Lines changed: 134 additions & 104 deletions
Original file line numberDiff line numberDiff line change
@@ -1,107 +1,4 @@
1-
export default CopyPlugin;
2-
export type Schema = import("schema-utils/declarations/validate").Schema;
3-
export type Compiler = import("webpack").Compiler;
4-
export type Compilation = import("webpack").Compilation;
5-
export type WebpackError = import("webpack").WebpackError;
6-
export type Asset = import("webpack").Asset;
7-
export type GlobbyOptions = import("globby").Options;
8-
export type GlobEntry = import("globby").GlobEntry;
9-
export type WebpackLogger = ReturnType<Compilation["getLogger"]>;
10-
export type CacheFacade = ReturnType<Compilation["getCache"]>;
11-
export type Etag = ReturnType<
12-
ReturnType<Compilation["getCache"]>["getLazyHashedEtag"]
13-
>;
14-
export type Snapshot = ReturnType<
15-
Compilation["fileSystemInfo"]["mergeSnapshots"]
16-
>;
17-
export type Force = boolean;
18-
export type CopiedResult = {
19-
sourceFilename: string;
20-
absoluteFilename: string;
21-
filename: string;
22-
source: Asset["source"];
23-
force: Force | undefined;
24-
info: {
25-
[key: string]: string;
26-
};
27-
};
28-
export type StringPattern = string;
29-
export type NoErrorOnMissing = boolean;
30-
export type Context = string;
31-
export type From = string;
32-
export type ToFunction = (pathData: {
33-
context: string;
34-
absoluteFilename?: string;
35-
}) => string;
36-
export type To = string | ToFunction;
37-
export type ToType = "dir" | "file" | "template";
38-
export type TransformerFunction = (
39-
input: Buffer,
40-
absoluteFilename: string
41-
) => any;
42-
export type TransformerCacheObject =
43-
| {
44-
keys: {
45-
[key: string]: any;
46-
};
47-
}
48-
| {
49-
keys: (
50-
defaultCacheKeys: {
51-
[key: string]: any;
52-
},
53-
absoluteFilename: string
54-
) => Promise<{
55-
[key: string]: any;
56-
}>;
57-
};
58-
export type TransformerObject = {
59-
transformer: TransformerFunction;
60-
cache?: boolean | TransformerCacheObject | undefined;
61-
};
62-
export type Transform = TransformerFunction | TransformerObject;
63-
export type Filter = (filepath: string) => any;
64-
export type TransformAllFunction = (
65-
data: {
66-
data: Buffer;
67-
sourceFilename: string;
68-
absoluteFilename: string;
69-
}[]
70-
) => any;
71-
export type Info =
72-
| {
73-
[key: string]: string;
74-
}
75-
| ((item: {
76-
absoluteFilename: string;
77-
sourceFilename: string;
78-
filename: string;
79-
toType: ToType;
80-
}) => {
81-
[key: string]: string;
82-
});
83-
export type ObjectPattern = {
84-
from: From;
85-
globOptions?: import("globby").Options | undefined;
86-
context?: string | undefined;
87-
to?: To | undefined;
88-
toType?: ToType | undefined;
89-
info?: Info | undefined;
90-
filter?: Filter | undefined;
91-
transform?: Transform | undefined;
92-
transformAll?: TransformAllFunction | undefined;
93-
force?: boolean | undefined;
94-
priority?: number | undefined;
95-
noErrorOnMissing?: boolean | undefined;
96-
};
97-
export type Pattern = StringPattern | ObjectPattern;
98-
export type AdditionalOptions = {
99-
concurrency?: number | undefined;
100-
};
101-
export type PluginOptions = {
102-
patterns: Pattern[];
103-
options?: AdditionalOptions | undefined;
104-
};
1+
export = CopyPlugin;
1052
/** @typedef {import("schema-utils/declarations/validate").Schema} Schema */
1063
/** @typedef {import("webpack").Compiler} Compiler */
1074
/** @typedef {import("webpack").Compilation} Compilation */
@@ -257,3 +154,136 @@ declare class CopyPlugin {
257154
*/
258155
apply(compiler: Compiler): void;
259156
}
157+
declare namespace CopyPlugin {
158+
export {
159+
Schema,
160+
Compiler,
161+
Compilation,
162+
WebpackError,
163+
Asset,
164+
GlobbyOptions,
165+
GlobEntry,
166+
WebpackLogger,
167+
CacheFacade,
168+
Etag,
169+
Snapshot,
170+
Force,
171+
CopiedResult,
172+
StringPattern,
173+
NoErrorOnMissing,
174+
Context,
175+
From,
176+
ToFunction,
177+
To,
178+
ToType,
179+
TransformerFunction,
180+
TransformerCacheObject,
181+
TransformerObject,
182+
Transform,
183+
Filter,
184+
TransformAllFunction,
185+
Info,
186+
ObjectPattern,
187+
Pattern,
188+
AdditionalOptions,
189+
PluginOptions,
190+
};
191+
}
192+
type Compiler = import("webpack").Compiler;
193+
type PluginOptions = {
194+
patterns: Pattern[];
195+
options?: AdditionalOptions | undefined;
196+
};
197+
type Schema = import("schema-utils/declarations/validate").Schema;
198+
type Compilation = import("webpack").Compilation;
199+
type WebpackError = import("webpack").WebpackError;
200+
type Asset = import("webpack").Asset;
201+
type GlobbyOptions = import("globby").Options;
202+
type GlobEntry = import("globby").GlobEntry;
203+
type WebpackLogger = ReturnType<Compilation["getLogger"]>;
204+
type CacheFacade = ReturnType<Compilation["getCache"]>;
205+
type Etag = ReturnType<
206+
ReturnType<Compilation["getCache"]>["getLazyHashedEtag"]
207+
>;
208+
type Snapshot = ReturnType<Compilation["fileSystemInfo"]["mergeSnapshots"]>;
209+
type Force = boolean;
210+
type CopiedResult = {
211+
sourceFilename: string;
212+
absoluteFilename: string;
213+
filename: string;
214+
source: Asset["source"];
215+
force: Force | undefined;
216+
info: {
217+
[key: string]: string;
218+
};
219+
};
220+
type StringPattern = string;
221+
type NoErrorOnMissing = boolean;
222+
type Context = string;
223+
type From = string;
224+
type ToFunction = (pathData: {
225+
context: string;
226+
absoluteFilename?: string;
227+
}) => string;
228+
type To = string | ToFunction;
229+
type ToType = "dir" | "file" | "template";
230+
type TransformerFunction = (input: Buffer, absoluteFilename: string) => any;
231+
type TransformerCacheObject =
232+
| {
233+
keys: {
234+
[key: string]: any;
235+
};
236+
}
237+
| {
238+
keys: (
239+
defaultCacheKeys: {
240+
[key: string]: any;
241+
},
242+
absoluteFilename: string
243+
) => Promise<{
244+
[key: string]: any;
245+
}>;
246+
};
247+
type TransformerObject = {
248+
transformer: TransformerFunction;
249+
cache?: boolean | TransformerCacheObject | undefined;
250+
};
251+
type Transform = TransformerFunction | TransformerObject;
252+
type Filter = (filepath: string) => any;
253+
type TransformAllFunction = (
254+
data: {
255+
data: Buffer;
256+
sourceFilename: string;
257+
absoluteFilename: string;
258+
}[]
259+
) => any;
260+
type Info =
261+
| {
262+
[key: string]: string;
263+
}
264+
| ((item: {
265+
absoluteFilename: string;
266+
sourceFilename: string;
267+
filename: string;
268+
toType: ToType;
269+
}) => {
270+
[key: string]: string;
271+
});
272+
type ObjectPattern = {
273+
from: From;
274+
globOptions?: import("globby").Options | undefined;
275+
context?: string | undefined;
276+
to?: To | undefined;
277+
toType?: ToType | undefined;
278+
info?: Info | undefined;
279+
filter?: Filter | undefined;
280+
transform?: Transform | undefined;
281+
transformAll?: TransformAllFunction | undefined;
282+
force?: boolean | undefined;
283+
priority?: number | undefined;
284+
noErrorOnMissing?: boolean | undefined;
285+
};
286+
type Pattern = StringPattern | ObjectPattern;
287+
type AdditionalOptions = {
288+
concurrency?: number | undefined;
289+
};

0 commit comments

Comments
 (0)