Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: reduce package size, avoid *.d.ts #4353

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions packages/create-webpack-app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,12 @@
"bin",
"lib",
"templates",
"!**/*__tests__"
"!**/*__tests__",
"!**/*.d.ts"
],
"dependencies": {
"@inquirer/prompts": "^7.2.0",
"@inquirer/expand": "^4.0.3",
"@inquirer/select": "^4.0.3",
"colorette": "^2.0.20",
"commander": "^12.1.0",
"cross-spawn": "^7.0.3",
Expand Down
12 changes: 6 additions & 6 deletions packages/create-webpack-app/src/generators/init/default.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ export default async function (plop: NodePlopAPI) {
// dependencies to be installed
const devDependencies: Array<string> = ["webpack", "webpack-cli"];

await plop.load("../../utils/pkgInstallAction.js", {}, true);
await plop.load("../../utils/fileGenerator.js", {}, true);
await plop.load("../../utils/install-dependencies.js", {}, true);
await plop.load("../../utils/generate-files.js", {}, true);

plop.setDefaultInclude({ generators: true, actionTypes: true });
plop.setPlopfilePath(resolve(__dirname, "../../plopfile.js"));
Expand Down Expand Up @@ -50,7 +50,7 @@ export default async function (plop: NodePlopAPI) {
name: "cssType",
message: "Which of the following CSS solution do you want to use?",
choices: ["none", "CSS only", "SASS", "LESS", "Stylus"],
default: "none",
default: "CSS only",
filter: (input, answers) => {
if (input === "none") {
answers.isCSS = false;
Expand Down Expand Up @@ -81,7 +81,7 @@ export default async function (plop: NodePlopAPI) {
name: "extractPlugin",
message: "Do you want to extract CSS into separate files?",
choices: ["No", "Only for Production", "Yes"],
default: "No",
default: "Only for Production",
},
{
type: "list",
Expand Down Expand Up @@ -181,7 +181,7 @@ export default async function (plop: NodePlopAPI) {

for (const file of files) {
actions.push({
type: "fileGenerator",
type: "generate-files",
path: join(answers.projectPath, file.filePath),
templateFile: join(
plop.getPlopfilePath(),
Expand All @@ -194,7 +194,7 @@ export default async function (plop: NodePlopAPI) {
}

actions.push({
type: "pkgInstall",
type: "install-dependencies",
path: answers.projectPath,
packages: devDependencies,
});
Expand Down
10 changes: 5 additions & 5 deletions packages/create-webpack-app/src/generators/init/react.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ export default async function (plop: NodePlopAPI) {
"@types/react-router-dom",
];

await plop.load("../../utils/pkgInstallAction.js", {}, true);
await plop.load("../../utils/fileGenerator.js", {}, true);
await plop.load("../../utils/install-dependencies.js", {}, true);
await plop.load("../../utils/generate-files.js", {}, true);

plop.setDefaultInclude({ generators: true, actionTypes: true });
plop.setPlopfilePath(resolve(__dirname, "../../plopfile.js"));
Expand Down Expand Up @@ -84,7 +84,7 @@ export default async function (plop: NodePlopAPI) {
name: "extractPlugin",
message: "Do you want to extract CSS into separate files?",
choices: ["No", "Only for Production", "Yes"],
default: "No",
default: "Only for Production",
},
{
type: "list",
Expand Down Expand Up @@ -201,7 +201,7 @@ export default async function (plop: NodePlopAPI) {

for (const file of files) {
actions.push({
type: "fileGenerator",
type: "generate-files",
path: join(answers.projectPath, file.filePath),
templateFile: join(
plop.getPlopfilePath(),
Expand All @@ -214,7 +214,7 @@ export default async function (plop: NodePlopAPI) {
}

actions.push({
type: "pkgInstall",
type: "install-dependencies",
path: answers.projectPath,
packages: devDependencies,
});
Expand Down
10 changes: 5 additions & 5 deletions packages/create-webpack-app/src/generators/init/svelte.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ export default async function (plop: NodePlopAPI) {
"html-webpack-plugin",
];

await plop.load("../../utils/pkgInstallAction.js", {}, true);
await plop.load("../../utils/fileGenerator.js", {}, true);
await plop.load("../../utils/install-dependencies.js", {}, true);
await plop.load("../../utils/generate-files.js", {}, true);

plop.setDefaultInclude({ generators: true, actionTypes: true });
plop.setPlopfilePath(resolve(__dirname, "../../plopfile.js"));
Expand Down Expand Up @@ -75,7 +75,7 @@ export default async function (plop: NodePlopAPI) {
name: "extractPlugin",
message: "Do you want to extract CSS into separate files?",
choices: ["No", "Only for Production", "Yes"],
default: "No",
default: "Only for Production",
},
{
type: "list",
Expand Down Expand Up @@ -188,7 +188,7 @@ export default async function (plop: NodePlopAPI) {

for (const file of files) {
actions.push({
type: "fileGenerator",
type: "generate-files",
path: join(answers.projectPath, file.filePath),
templateFile: join(
plop.getPlopfilePath(),
Expand All @@ -201,7 +201,7 @@ export default async function (plop: NodePlopAPI) {
}

actions.push({
type: "pkgInstall",
type: "install-dependencies",
path: answers.projectPath,
packages: devDependencies,
});
Expand Down
10 changes: 5 additions & 5 deletions packages/create-webpack-app/src/generators/init/vue.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ export default async function (plop: NodePlopAPI) {
"vue-router@4",
];

await plop.load("../../utils/pkgInstallAction.js", {}, true);
await plop.load("../../utils/fileGenerator.js", {}, true);
await plop.load("../../utils/install-dependencies.js", {}, true);
await plop.load("../../utils/generate-files.js", {}, true);

plop.setDefaultInclude({ generators: true, actionTypes: true });
plop.setPlopfilePath(resolve(__dirname, "../../plopfile.js"));
Expand Down Expand Up @@ -83,7 +83,7 @@ export default async function (plop: NodePlopAPI) {
name: "extractPlugin",
message: "Do you want to extract CSS into separate files?",
choices: ["No", "Only for Production", "Yes"],
default: "No",
default: "Only for Production",
},
{
type: "list",
Expand Down Expand Up @@ -210,7 +210,7 @@ export default async function (plop: NodePlopAPI) {

for (const file of files) {
actions.push({
type: "fileGenerator",
type: "generate-files",
path: join(answers.projectPath, file.filePath),
templateFile: join(
plop.getPlopfilePath(),
Expand All @@ -223,7 +223,7 @@ export default async function (plop: NodePlopAPI) {
}

actions.push({
type: "pkgInstall",
type: "install-dependencies",
path: answers.projectPath,
packages: devDependencies,
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ export default async function (plop: NodePlopAPI) {
// dependencies to be installed
const devDependencies: Array<string> = ["webpack-defaults"];

await plop.load("../../utils/pkgInstallAction.js", {}, true);
await plop.load("../../utils/fileGenerator.js", {}, true);
await plop.load("../../utils/install-dependencies.js", {}, true);
await plop.load("../../utils/generate-files.js", {}, true);

// custom helper function
plop.setHelper("makeLoaderName", (name: string) => {
Expand Down Expand Up @@ -76,7 +76,7 @@ export default async function (plop: NodePlopAPI) {

for (const file of files) {
actions.push({
type: "fileGenerator",
type: "generate-files",
path: join(answers.projectPath, file.filePath),
templateFile: join(
plop.getPlopfilePath(),
Expand All @@ -89,7 +89,7 @@ export default async function (plop: NodePlopAPI) {
}

actions.push({
type: "pkgInstall",
type: "install-dependencies",
path: answers.projectPath,
packages: devDependencies,
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ export default async function (plop: NodePlopAPI) {
// dependencies to be installed
const devDependencies: Array<string> = ["webpack-defaults"];

await plop.load("../../utils/pkgInstallAction.js", {}, true);
await plop.load("../../utils/fileGenerator.js", {}, true);
await plop.load("../../utils/install-dependencies.js", {}, true);
await plop.load("../../utils/generate-files.js", {}, true);

plop.setDefaultInclude({ generators: true, actionTypes: true });
plop.setPlopfilePath(resolve(__dirname, "../../plopfile.js"));
Expand Down Expand Up @@ -68,7 +68,7 @@ export default async function (plop: NodePlopAPI) {

for (const file of files) {
actions.push({
type: "fileGenerator",
type: "generate-files",
path: join(answers.projectPath, file.filePath),
templateFile: join(
plop.getPlopfilePath(),
Expand All @@ -81,7 +81,7 @@ export default async function (plop: NodePlopAPI) {
}

actions.push({
type: "pkgInstall",
type: "install-dependencies",
path: answers.projectPath,
packages: devDependencies,
});
Expand Down
2 changes: 1 addition & 1 deletion packages/create-webpack-app/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Command } from "commander";
import { resolve, dirname } from "path";
import { select } from "@inquirer/prompts";
import select from "@inquirer/select";
import nodePlop, { type PlopGenerator } from "node-plop";
import { fileURLToPath } from "url";

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as fs from "fs/promises";
import * as ejs from "ejs";
import { expand } from "@inquirer/prompts";
import expand from "@inquirer/expand";
import { spawn, sync } from "cross-spawn";
import * as path from "path";
import { fileURLToPath } from "url";
Expand Down Expand Up @@ -240,7 +240,7 @@ export default async function (plop: NodePlopAPI) {
plop.setPlopfilePath(path.resolve(__dirname, "../plopfile.js"));
plop.setDefaultInclude({ actions: true });

plop.setActionType("fileGenerator", async (answers, config) => {
plop.setActionType("generate-files", async (answers, config) => {
const isTemplate = config.fileType === "text";
const result = await checkAndPrepareContent(
{ ...config, data: answers } as AddConfig,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export default async function (plop: NodePlopAPI) {

plop.setPlopfilePath(resolve(__dirname, "../plopfile.js"));
plop.setDefaultInclude({ actions: true });
plop.setActionType("pkgInstall", (answers, config) => {
plop.setActionType("install-dependencies", (answers, config) => {
const options: SpawnOptionsWithStdioTuple<
StdioNull,
StdioNull | StdioPipe,
Expand All @@ -30,7 +30,7 @@ export default async function (plop: NodePlopAPI) {

// promise to complete subprocess of installing packages and return a message
const returnPromise: Promise<string> = new Promise((resolve, reject) => {
const returnMessage = `Project Dependencies installed successfully`;
const returnMessage = `Project dependencies installed successfully!`;
const packageManager = answers.packageManager;
const packages = config.packages.length == 1 ? [config.packages[0]] : config.packages;
const installOptions: Record<string, Array<string>> = {
Expand Down
21 changes: 15 additions & 6 deletions packages/create-webpack-app/src/utils/logger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,21 @@ const typeDisplay: Record<string, Color | string> = {
};

function onSuccessHandler(change: PlopActionHooksChanges): void {
change.path.split("\n").forEach((line) => {
const [operationType = "", renderPath = ""] = line.split("|") as [string, string];
console.log(
`\t${typeDisplay[operationType]} ${normalize(relative(process.cwd(), renderPath))}`,
);
});
switch (change.type) {
case "generate-files": {
change.path.split("\n").forEach((line) => {
const [operationType = "", renderPath = ""] = line.split("|");
console.log(
`\t${typeDisplay[operationType]} ${normalize(relative(process.cwd(), renderPath))}`,
);
});
break;
}
case "install-dependencies": {
logger.success(change.path);
break;
}
}
}

function onFailureHandler(failure: PlopActionHooksFailures): void {
Expand Down
Loading