Skip to content

Commit

Permalink
🐛 Fix(Configs,myplop): config issues and lint/format errors in myplop
Browse files Browse the repository at this point in the history
add to eslint ignore file (prerttier file config at myplop), repair errors of lint and format at myplop, webpack config error in dev and build (prod)
  • Loading branch information
INeedJobToStartWork committed Jan 25, 2024
1 parent eeb1015 commit e6d3d8b
Show file tree
Hide file tree
Showing 19 changed files with 167 additions and 255 deletions.
94 changes: 47 additions & 47 deletions .lintstagedrc.mjs
Original file line number Diff line number Diff line change
@@ -1,53 +1,53 @@
import { readFileSync, readdirSync, statSync } from "fs";
import yaml from "js-yaml";
import path, { join, resolve } from "path";
// import { readFileSync, readdirSync, statSync } from "fs";
// import yaml from "js-yaml";
// import path, { join, resolve } from "path";

const AllWorkspaceNames = async () => {
const parsedWorkspaces = await yaml.load(
readFileSync("./pnpm-workspace.yaml", "utf8")
);
const result = await Promise.all(
parsedWorkspaces.packages.map(async (workspace) => {
const path = join(process.cwd(), workspace).replace("*", "");
// const AllWorkspaceNames = async () => {
// const parsedWorkspaces = await yaml.load(
// readFileSync("./pnpm-workspace.yaml", "utf8")
// );
// const result = await Promise.all(
// parsedWorkspaces.packages.map(async (workspace) => {
// const path = join(process.cwd(), workspace).replace("*", "");

const dirPackageJson = readdirSync(path)
.filter((file) => {
const filePath = join(path, file);
return (
statSync(filePath).isDirectory() &&
readdirSync(filePath).includes("package.json")
);
})
.map((directory) => join(path, directory, "package.json"));
// const dirPackageJson = readdirSync(path)
// .filter((file) => {
// const filePath = join(path, file);
// return (
// statSync(filePath).isDirectory() &&
// readdirSync(filePath).includes("package.json")
// );
// })
// .map((directory) => join(path, directory, "package.json"));

const WorkspacesName = await Promise.all(
dirPackageJson.map(async (packageJson) => {
const res = await import(`file://${packageJson}`, {
assert: { type: "json" },
});
return res.default.name;
})
);
// const WorkspacesName = await Promise.all(
// dirPackageJson.map(async (packageJson) => {
// const res = await import(`file://${packageJson}`, {
// assert: { type: "json" },
// });
// return res.default.name;
// })
// );

return WorkspacesName;
})
);
return result.flat(Infinity);
};

const prompts = async () => {
const result = (await AllWorkspaceNames()).map(
(workspace) => `pnpm pre --filter ${workspace} --`
);
return result;
};

// export default {
// "*": ["pnpm turbo test"],
// return WorkspacesName;
// })
// );
// return result.flat(Infinity);
// };
export default {
"*": [...(await prompts())],
};
// export default {
// "./config/eslintrc": "pnpm pre --filter eslintrc",

// const prompts = async () => {
// const result = (await AllWorkspaceNames()).map(
// (workspace) => `pnpm pre --filter ${workspace} --`
// );
// return result;
// };

// // export default {
// // "*": ["pnpm turbo test"],
// // };
// // export default {
// // "*": [...(await prompts())],
// // };
// // export default {
// // "./config/eslintrc": "pnpm pre --filter eslintrc",
// // };
8 changes: 6 additions & 2 deletions config/eslintrc/base.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,12 @@ export default [
"@EslintPii": EslintPii,
"@EslintSecurity": EslintSecurity,
"@EslintSortKeys": EslintSortKeys,
"@stylistic/js": stylisticJs
"@stylistic/js": stylisticJs,


},
rules: {

"array-callback-return": "error",
"constructor-super": "error",
"for-direction": "error",
Expand Down Expand Up @@ -275,7 +278,8 @@ export default [

"@stylistic/js/space-unary-ops": "error",
"@stylistic/js/spaced-comment": ["error", "always"],
"@stylistic/js/template-tag-spacing": ["error", "always"]
"@stylistic/js/template-tag-spacing": ["error", "always"],

}
}
];
2 changes: 1 addition & 1 deletion config/eslintrc/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
"pre": "echo 'Add test script here'"
},
"devDependencies": {
"@typescript-eslint/eslint-plugin": "^6.16.0",
"@stylistic/eslint-plugin": "^1.5.1",
"@typescript-eslint/eslint-plugin": "^6.16.0",
"eslint-plugin-optimize-regex": "^1.2.1",
"eslint-plugin-pii": "^1.0.2",
"eslint-plugin-security": "^2.1.0",
Expand Down
2 changes: 1 addition & 1 deletion config/prettierrc/.prettierrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"bracketSameLine": true,
"bracketSpacing": true,
"cursorOffset": -1,
"plugins": ["@trivago/prettier-plugin-sort-imports", "prettier-plugin-packagejson"],
"plugins": ["prettier-plugin-packagejson"],
"printWidth": 120,
"proseWrap": "always",
"tabWidth": 2,
Expand Down
1 change: 0 additions & 1 deletion config/prettierrc/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
"test": "echo 'Add test script here'"
},
"devDependencies": {
"@trivago/prettier-plugin-sort-imports": "^4.3.0",
"prettier": "^3.1.1",
"prettier-plugin-packagejson": "^2.4.8"
}
Expand Down
29 changes: 29 additions & 0 deletions config/tsconfig/base.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
{
"$schema": "https://json.schemastore.org/tsconfig",
"compilerOptions": {
"lib": ["esnext", "dom"],
"module": "ESNext",
"moduleResolution": "Bundler",
"target": "ES6",
"allowUnreachableCode": false,
"allowUnusedLabels": false,
"alwaysStrict": false,
"exactOptionalPropertyTypes": false,
"noFallthroughCasesInSwitch": false,
"noImplicitAny": true,
"noImplicitOverride": true,
"noImplicitReturns": true,
"noImplicitThis": true,
"noPropertyAccessFromIndexSignature": false,
"noUnusedLocals": true,
"noUnusedParameters": true,
"strict": true,
"strictBindCallApply": true,
"strictFunctionTypes": true,
"strictNullChecks": true,
"strictPropertyInitialization": true,
"resolveJsonModule": true
},
"display": "default",
"exclude": ["node_modules", "dist", "lib"]
}
6 changes: 3 additions & 3 deletions config/webpackrc/webpack.base.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,9 @@ export default {
}
},
plugins: [
new CopyPlugin({
patterns: [{ from: path.resolve(__dirname, "./src/templates"), to: path.join(PATHOUT, "templates") }]
})
// new CopyPlugin({
// patterns: [{ from: path.resolve(__dirname, "./src/templates"), to: path.join(PATHOUT, "templates") }]
// })
],
target: "node"
};
2 changes: 1 addition & 1 deletion packages/myplop/.prettierignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
*.hbs
dist/*
lib/*
lib/*
2 changes: 1 addition & 1 deletion packages/myplop/README.md
Original file line number Diff line number Diff line change
@@ -1 +1 @@
# `myplop`
# `myplop`
5 changes: 3 additions & 2 deletions packages/myplop/config/webpack/webpack.base.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import WebpackConfig from 'webpackrc/webpack.base.js';
import {merge} from "webpack-merge";
import { merge } from "webpack-merge";
import WebpackConfig from "webpackrc/webpack.base.js";

export default merge(WebpackConfig, {});
5 changes: 3 additions & 2 deletions packages/myplop/config/webpack/webpack.dev.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import WebpackConfigDev from 'webpackrc/webpack.dev.js';
import {merge} from "webpack-merge";
import { merge } from "webpack-merge";
import WebpackConfigDev from "webpackrc/webpack.dev.js";

export default merge(WebpackConfigDev, {});
5 changes: 3 additions & 2 deletions packages/myplop/config/webpack/webpack.prod.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import WebpackConfigProd from 'webpackrc/webpack.dev.js';
import {merge} from "webpack-merge";
import { merge } from "webpack-merge";
import WebpackConfigProd from "webpackrc/webpack.prod.js";

export default merge(WebpackConfigProd, {});
1 change: 1 addition & 0 deletions packages/myplop/dist/index.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
console.log("Hello World!"),module.exports={}.default;
2 changes: 1 addition & 1 deletion packages/myplop/eslint.config.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import EslintBase from "eslintrc/base.js";
import EslintTypescript from "eslintrc/typescript.js";

export default [...EslintBase, ...EslintTypescript];
export default [{ ignores: ["prettier.config.js"] }, ...EslintBase, ...EslintTypescript];
73 changes: 41 additions & 32 deletions packages/myplop/package.json
Original file line number Diff line number Diff line change
@@ -1,36 +1,45 @@
{
"name": "myplop",
"version": "0.0.0",
"type": "module",
"private": false,
"scripts": {
"pre": "echo 'Add test script here'",
"test": "echo 'Add test script here'",
"build": "webpack --config ./config/webpack/webpack.prod.js",
"build:npm": "pnpm npm:prepack && webpack --config ./config/webpack/webpack.prod.js && pnpm npm:postpack ",
"dev": "webpack --config ./config/webpack/webpack.dev.js",
"lint": "eslint .",
"lint:fix": "eslint . --fix",
"format": "pnpm prettier . --write && pnpm prettier . --check",
"npm:prepack": "clean-package",
"npm:postpack": "clean-package restore",
"npm:publish": "npm publish",
"link-cli": "pnpm unlink --global && pnpm link --global",
"name": "myplop",
"version": "0.0.0",
"private": false,
"type": "module",
"scripts": {
"build": "webpack --config ./config/webpack/webpack.prod.js",
"build:npm": "pnpm npm:prepack && webpack --config ./config/webpack/webpack.prod.js && pnpm npm:postpack ",
"dev": "webpack --config ./config/webpack/webpack.dev.js",
"format": "pnpm prettier . --write && pnpm prettier . --check",
"link-cli": "pnpm unlink --global && pnpm link --global",
"link-cli:dev": "cd lib && pnpm unlink --global && pnpm link --global",
"lint": "eslint .",
"lint:fix": "eslint . --fix",
"npm:postpack": "clean-package restore",
"npm:prepack": "clean-package",
"npm:publish": "npm publish",
"pre": "echo 'Add test script here'",
"test": "echo 'Add test script here'",
"unlink-cli": "cd lib && pnpm unlink --global",
"unlink-cli:dev": "cd lib && pnpm unlink --global "
},
"devDependencies": {
"bundle-declarations-webpack-plugin": "^5.0.0",
"clean-package": "^2.2.0",
"copy-webpack-plugin": "^12.0.1",
"eslintrc": "workspace:*",
"prettierrc": "workspace:*",
"swc-loader": "^0.2.3",
"typescript": "^5.3.3",
"webpack": "^5.89.0",
"webpack-cli": "^5.1.4",
"webpack-merge": "^5.10.0",
"webpackrc": "workspace:*"
}
}
},
"lint-staged": {
"*": [
"pnpm format --",
"pnpm lint:fix --",
"pnpm lint --"
]
},
"devDependencies": {
"bundle-declarations-webpack-plugin": "^5.0.0",
"clean-package": "^2.2.0",
"copy-webpack-plugin": "^12.0.1",
"eslintrc": "workspace:*",
"prettier": "^3.1.1",
"prettierrc": "workspace:*",
"swc-loader": "^0.2.3",
"tsconfig": "workspace:*",
"typescript": "^5.3.3",
"webpack": "^5.89.0",
"webpack-cli": "^5.1.4",
"webpack-merge": "^5.10.0",
"webpackrc": "workspace:*"
}
}
8 changes: 5 additions & 3 deletions packages/myplop/prettier.config.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import prettierConfig from "prettierrc/.prettierrc.json"
// Eslint doesn't support `assert` because it's experimental
import prettierConfig from "prettierrc/.prettierrc.json" assert { type: "json" };

export default {
...prettierConfig,
}
...prettierConfig
};
2 changes: 1 addition & 1 deletion packages/myplop/src/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1 @@
console.log("Hello World!")
console.log("Hello World!");
14 changes: 14 additions & 0 deletions packages/myplop/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"$schema": "http://json.schemastore.org/tsconfig",
"compilerOptions": {
"declaration": true,

"outDir": "./dist",
"baseUrl": "./src",
"paths": {
"@/*": ["*"]
}
},
// "include": ["src"],
"extends": "tsconfig/base.json"
}
Loading

0 comments on commit e6d3d8b

Please sign in to comment.