diff --git a/package.json b/package.json index 0786a74..e7f5f52 100644 --- a/package.json +++ b/package.json @@ -11,14 +11,14 @@ "type": "opencollective", "url": "https://opencollective.com/webpack" }, - "main": "dist/cjs.js", - "types": "types/cjs.d.ts", + "main": "dist/index.js", + "types": "types/index.d.ts", "engines": { "node": ">= 12.20.0" }, "scripts": { "start": "npm run build -- -w", - "clean": "del-cli dist", + "clean": "del-cli dist types", "prebuild": "npm run clean", "build:types": "tsc --declaration --emitDeclarationOnly --outDir types --rootDir src && prettier \"types/**/*.ts\" --write", "build:code": "cross-env NODE_ENV=production babel src -d dist --copy-files", diff --git a/src/cjs.js b/src/cjs.js deleted file mode 100644 index 54bc4ed..0000000 --- a/src/cjs.js +++ /dev/null @@ -1,3 +0,0 @@ -const plugin = require("./index"); - -module.exports = plugin.default; diff --git a/src/index.js b/src/index.js index 6b49016..caada0e 100644 --- a/src/index.js +++ b/src/index.js @@ -1,16 +1,16 @@ -import path from "path"; +const path = require("path"); -import { validate } from "schema-utils"; -import serialize from "serialize-javascript"; -import normalizePath from "normalize-path"; -import globParent from "glob-parent"; -import fastGlob from "fast-glob"; +const { validate } = require("schema-utils"); +const serialize = require("serialize-javascript"); +const normalizePath = require("normalize-path"); +const globParent = require("glob-parent"); +const fastGlob = require("fast-glob"); // @ts-ignore -import { version } from "../package.json"; +const { version } = require("../package.json"); -import schema from "./options.json"; -import { readFile, stat, throttleAll } from "./utils"; +const schema = require("./options.json"); +const { readFile, stat, throttleAll } = require("./utils"); const template = /\[\\*([\w:]+)\\*\]/i; @@ -1096,4 +1096,4 @@ class CopyPlugin { } } -export default CopyPlugin; +module.exports = CopyPlugin; diff --git a/src/utils.js b/src/utils.js index 0ec4355..b13ba82 100644 --- a/src/utils.js +++ b/src/utils.js @@ -119,4 +119,4 @@ function throttleAll(limit, tasks) { }); } -export { stat, readFile, throttleAll }; +module.exports = { stat, readFile, throttleAll }; diff --git a/test/cjs.test.js b/test/cjs.test.js deleted file mode 100644 index 754af8f..0000000 --- a/test/cjs.test.js +++ /dev/null @@ -1,8 +0,0 @@ -import src from "../src/index"; -import cjs from "../src/cjs"; - -describe("cjs", () => { - it("should exported", () => { - expect(cjs).toEqual(src); - }); -}); diff --git a/types/cjs.d.ts b/types/cjs.d.ts deleted file mode 100644 index 2cb80fb..0000000 --- a/types/cjs.d.ts +++ /dev/null @@ -1,3 +0,0 @@ -declare const _exports: typeof plugin.default; -export = _exports; -import plugin = require("./index"); diff --git a/types/index.d.ts b/types/index.d.ts index 4920c2f..850db6f 100644 --- a/types/index.d.ts +++ b/types/index.d.ts @@ -1,107 +1,4 @@ -export default CopyPlugin; -export type Schema = import("schema-utils/declarations/validate").Schema; -export type Compiler = import("webpack").Compiler; -export type Compilation = import("webpack").Compilation; -export type WebpackError = import("webpack").WebpackError; -export type Asset = import("webpack").Asset; -export type GlobbyOptions = import("globby").Options; -export type GlobEntry = import("globby").GlobEntry; -export type WebpackLogger = ReturnType; -export type CacheFacade = ReturnType; -export type Etag = ReturnType< - ReturnType["getLazyHashedEtag"] ->; -export type Snapshot = ReturnType< - Compilation["fileSystemInfo"]["mergeSnapshots"] ->; -export type Force = boolean; -export type CopiedResult = { - sourceFilename: string; - absoluteFilename: string; - filename: string; - source: Asset["source"]; - force: Force | undefined; - info: { - [key: string]: string; - }; -}; -export type StringPattern = string; -export type NoErrorOnMissing = boolean; -export type Context = string; -export type From = string; -export type ToFunction = (pathData: { - context: string; - absoluteFilename?: string; -}) => string; -export type To = string | ToFunction; -export type ToType = "dir" | "file" | "template"; -export type TransformerFunction = ( - input: Buffer, - absoluteFilename: string -) => any; -export type TransformerCacheObject = - | { - keys: { - [key: string]: any; - }; - } - | { - keys: ( - defaultCacheKeys: { - [key: string]: any; - }, - absoluteFilename: string - ) => Promise<{ - [key: string]: any; - }>; - }; -export type TransformerObject = { - transformer: TransformerFunction; - cache?: boolean | TransformerCacheObject | undefined; -}; -export type Transform = TransformerFunction | TransformerObject; -export type Filter = (filepath: string) => any; -export type TransformAllFunction = ( - data: { - data: Buffer; - sourceFilename: string; - absoluteFilename: string; - }[] -) => any; -export type Info = - | { - [key: string]: string; - } - | ((item: { - absoluteFilename: string; - sourceFilename: string; - filename: string; - toType: ToType; - }) => { - [key: string]: string; - }); -export type ObjectPattern = { - from: From; - globOptions?: import("globby").Options | undefined; - context?: string | undefined; - to?: To | undefined; - toType?: ToType | undefined; - info?: Info | undefined; - filter?: Filter | undefined; - transform?: Transform | undefined; - transformAll?: TransformAllFunction | undefined; - force?: boolean | undefined; - priority?: number | undefined; - noErrorOnMissing?: boolean | undefined; -}; -export type Pattern = StringPattern | ObjectPattern; -export type AdditionalOptions = { - concurrency?: number | undefined; -}; -export type PluginOptions = { - patterns: Pattern[]; - options?: AdditionalOptions | undefined; -}; +export = CopyPlugin; /** @typedef {import("schema-utils/declarations/validate").Schema} Schema */ /** @typedef {import("webpack").Compiler} Compiler */ /** @typedef {import("webpack").Compilation} Compilation */ @@ -257,3 +154,136 @@ declare class CopyPlugin { */ apply(compiler: Compiler): void; } +declare namespace CopyPlugin { + export { + Schema, + Compiler, + Compilation, + WebpackError, + Asset, + GlobbyOptions, + GlobEntry, + WebpackLogger, + CacheFacade, + Etag, + Snapshot, + Force, + CopiedResult, + StringPattern, + NoErrorOnMissing, + Context, + From, + ToFunction, + To, + ToType, + TransformerFunction, + TransformerCacheObject, + TransformerObject, + Transform, + Filter, + TransformAllFunction, + Info, + ObjectPattern, + Pattern, + AdditionalOptions, + PluginOptions, + }; +} +type Compiler = import("webpack").Compiler; +type PluginOptions = { + patterns: Pattern[]; + options?: AdditionalOptions | undefined; +}; +type Schema = import("schema-utils/declarations/validate").Schema; +type Compilation = import("webpack").Compilation; +type WebpackError = import("webpack").WebpackError; +type Asset = import("webpack").Asset; +type GlobbyOptions = import("globby").Options; +type GlobEntry = import("globby").GlobEntry; +type WebpackLogger = ReturnType; +type CacheFacade = ReturnType; +type Etag = ReturnType< + ReturnType["getLazyHashedEtag"] +>; +type Snapshot = ReturnType; +type Force = boolean; +type CopiedResult = { + sourceFilename: string; + absoluteFilename: string; + filename: string; + source: Asset["source"]; + force: Force | undefined; + info: { + [key: string]: string; + }; +}; +type StringPattern = string; +type NoErrorOnMissing = boolean; +type Context = string; +type From = string; +type ToFunction = (pathData: { + context: string; + absoluteFilename?: string; +}) => string; +type To = string | ToFunction; +type ToType = "dir" | "file" | "template"; +type TransformerFunction = (input: Buffer, absoluteFilename: string) => any; +type TransformerCacheObject = + | { + keys: { + [key: string]: any; + }; + } + | { + keys: ( + defaultCacheKeys: { + [key: string]: any; + }, + absoluteFilename: string + ) => Promise<{ + [key: string]: any; + }>; + }; +type TransformerObject = { + transformer: TransformerFunction; + cache?: boolean | TransformerCacheObject | undefined; +}; +type Transform = TransformerFunction | TransformerObject; +type Filter = (filepath: string) => any; +type TransformAllFunction = ( + data: { + data: Buffer; + sourceFilename: string; + absoluteFilename: string; + }[] +) => any; +type Info = + | { + [key: string]: string; + } + | ((item: { + absoluteFilename: string; + sourceFilename: string; + filename: string; + toType: ToType; + }) => { + [key: string]: string; + }); +type ObjectPattern = { + from: From; + globOptions?: import("globby").Options | undefined; + context?: string | undefined; + to?: To | undefined; + toType?: ToType | undefined; + info?: Info | undefined; + filter?: Filter | undefined; + transform?: Transform | undefined; + transformAll?: TransformAllFunction | undefined; + force?: boolean | undefined; + priority?: number | undefined; + noErrorOnMissing?: boolean | undefined; +}; +type Pattern = StringPattern | ObjectPattern; +type AdditionalOptions = { + concurrency?: number | undefined; +};