Skip to content

Commit

Permalink
feat: drop cjs wrapper (#654)
Browse files Browse the repository at this point in the history
alexander-akait authored Dec 16, 2021

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
1 parent d6a6cdb commit 5901006
Showing 7 changed files with 148 additions and 132 deletions.
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -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",
3 changes: 0 additions & 3 deletions src/cjs.js

This file was deleted.

20 changes: 10 additions & 10 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -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;
2 changes: 1 addition & 1 deletion src/utils.js
Original file line number Diff line number Diff line change
@@ -119,4 +119,4 @@ function throttleAll(limit, tasks) {
});
}

export { stat, readFile, throttleAll };
module.exports = { stat, readFile, throttleAll };
8 changes: 0 additions & 8 deletions test/cjs.test.js

This file was deleted.

3 changes: 0 additions & 3 deletions types/cjs.d.ts

This file was deleted.

238 changes: 134 additions & 104 deletions types/index.d.ts
Original file line number Diff line number Diff line change
@@ -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<Compilation["getLogger"]>;
export type CacheFacade = ReturnType<Compilation["getCache"]>;
export type Etag = ReturnType<
ReturnType<Compilation["getCache"]>["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<Compilation["getLogger"]>;
type CacheFacade = ReturnType<Compilation["getCache"]>;
type Etag = ReturnType<
ReturnType<Compilation["getCache"]>["getLazyHashedEtag"]
>;
type Snapshot = ReturnType<Compilation["fileSystemInfo"]["mergeSnapshots"]>;
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;
};

0 comments on commit 5901006

Please sign in to comment.