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

WIP: Feat 6.5.4 #148

Closed
wants to merge 16 commits into from
Closed
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
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ jobs:
- name: Install pnpm
uses: pnpm/[email protected]
with:
version: 6.32.2
version: 7.33.0
- uses: actions/setup-node@v2
with:
node-version: 14.x
Expand Down
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@
"commitizen": "^4.3.0",
"cz-conventional-changelog": "^3.3.0",
"husky": "^8.0.3",
"prettier": "^2.8.4"
"prettier": "^2.8.4",
"typescript": "^4.6.4"
},
"packageManager": "pnpm@6.32.12"
"packageManager": "pnpm@7.33.0"
}
6 changes: 6 additions & 0 deletions packages/create-ko/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# create-ko

## 1.0.2

### Patch Changes

- 70ac1f4b9: add editorConfig file

## 1.0.1

### Patch Changes
Expand Down
2 changes: 1 addition & 1 deletion packages/create-ko/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "create-ko",
"version": "1.0.1",
"version": "1.0.2",
"description": "create react project with ko",
"repository": {
"type": "git",
Expand Down
9 changes: 9 additions & 0 deletions packages/create-ko/template/.editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
root = true

[*]
charset = utf-8
indent_style = space
indent_size = 4
end_of_line = lf
insert_final_newline = true
trim_trailing_whitespace = true
3 changes: 3 additions & 0 deletions packages/create-ko/template/ko.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ const finalKoConfig = (function () {
const APP_PATH = path.resolve(ROOT_PATH, 'src');
const BUILD_PATH = path.resolve(ROOT_PATH, `dist`);
const WEB_PUBLIC = path.resolve(APP_PATH, 'public');
/**
* @type {import("ko/lib/types").IOptions}
*/
const baseKoConfig = {
entry: path.join(APP_PATH, './main.tsx'),
outputPath: BUILD_PATH,
Expand Down
5 changes: 5 additions & 0 deletions packages/ko-lint-config/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# ko-lint-config

## 2.3.0

### Minor Changes

- 7921a2637: support [email protected]
## 2.2.21

### Patch Changes
Expand Down
8 changes: 5 additions & 3 deletions packages/ko-lint-config/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "ko-lint-config",
"version": "2.2.21",
"version": "2.3.0",
"description": "lint configs about eslint stylelint and prettier",
"main": "index.js",
"files": [
Expand Down Expand Up @@ -58,8 +58,10 @@
"stylelint-scss": "4.3.0"
},
"devDependencies": {
"tape": "^5.5.2",
"typescript": "4.7.4"
"tape": "^5.5.2"
},
"peerDependencies": {
"typescript": "^4.6.4"
},
"engines": {
"node": ">=14"
Expand Down
10 changes: 10 additions & 0 deletions packages/ko-lints/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
# ko-lints

## 5.0.0

### Minor Changes

- 7921a2637: support [email protected]

### Patch Changes

- Updated dependencies [7921a2637]
- [email protected]
## 4.0.21

### Patch Changes
Expand Down
6 changes: 3 additions & 3 deletions packages/ko-lints/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "ko-lints",
"version": "4.0.21",
"version": "5.0.0",
"description": "lint tools used by ko",
"keywords": [
"ko",
Expand Down Expand Up @@ -34,10 +34,10 @@
"fast-glob": "^3.2.11"
},
"peerDependencies": {
"ko-lint-config": "workspace:*"
"ko-lint-config": "workspace:*",
"typescript": "^4.6.4"
},
"devDependencies": {
"typescript": "^4.6.4",
"ko-lint-config": "workspace:*"
}
}
14 changes: 14 additions & 0 deletions packages/ko/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,19 @@
# ko

## 6.6.0

### Minor Changes

- 7921a2637: support [email protected]

### Patch Changes

- 81500dcee: auto purge expired cache files
- e76ee46e8: update webpack-dev-server to v4.14.0
- f7eef14db: add jsdoc and .d.ts file
- Updated dependencies [7921a2637]
- [email protected]

## 6.5.3

### Patch Changes
Expand Down
11 changes: 6 additions & 5 deletions packages/ko/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "ko",
"version": "6.5.3",
"version": "6.6.0",
"description": "build & lint library",
"keywords": [
"ko",
Expand Down Expand Up @@ -61,11 +61,10 @@
"css-minimizer-webpack-plugin": "^4.0.0",
"detect-port": "^1.3.0",
"dynamic-resolve-webpack-plugin": "workspace:^2.0.0",
"error-overlay-webpack-plugin": "^1.1.1",
"esbuild-loader": "^2.19.0",
"html-webpack-plugin": "^5.5.0",
"inquirer": "^8.2.2",
"ko-lints": "workspace:^4.0.0",
"ko-lints": "workspace:^5.0.0",
"less": "^3.13.1",
"less-loader": "^9.1.0",
"lodash": "^4.17.21",
Expand All @@ -85,7 +84,7 @@
"thread-loader": "^3.0.4",
"webpack": "^5.72.1",
"webpack-bundle-analyzer": "^4.5.0",
"webpack-dev-server": "4.9.0",
"webpack-dev-server": "4.14.0",
"webpackbar": "^5.0.2",
"worker-loader": "^3.0.8"
},
Expand All @@ -97,7 +96,9 @@
"@types/lodash": "^4.14.182",
"@types/webpack-bundle-analyzer": "^4.4.1",
"jest": "^28.1.0",
"ts-jest": "^28.0.3",
"ts-jest": "^28.0.3"
},
"peerDependencies": {
"typescript": "^4.6.4"
},
"engines": {
Expand Down
6 changes: 5 additions & 1 deletion packages/ko/src/actions/dev.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,11 @@ class Dev extends ActionFactory {
setupExitSignals: false,
allowedHosts: 'all',
client: {
overlay: false,
overlay: {
errors: true,
warnings: false,
runtimeErrors: true,
},
},
historyApiFallback,
};
Expand Down
72 changes: 72 additions & 0 deletions packages/ko/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,24 +5,88 @@ import { IOpts as AutoPolyfillsWebpackPluginOptions } from 'auto-polyfills-webpa

export type IOptions = {
//common configs
/**
* The current working directory.
* @param {string}
*/
cwd: string;
/**
* An object mapping module names to file paths or directories.
* @param {Record<string, string>}
*/
alias?: Record<string, string>;
/**
* An array of patterns specifying files to copy to the output directory.
* @param {Pattern[]}
*/
copy?: Pattern[];
/**
* The entry point of the application.
* @param {string}
*/
entry?: string;
/**
* The path to the output directory.
* @param {string}
*/
outputPath?: string;
/**
* The public path of the application.
* @param {string}
*/
publicPath?: string;
/**
* Whether to append a hash to the output file name for cache busting.
* @param {boolean}
*/
hash?: boolean;
/**
* An object mapping module names to global variables.
* @param {Record<string, string>}
*/
externals?: Record<string, string>;
/**
* An array of plugin configurations.
* @param {HookOptions[]}
*/
plugins?: HookOptions[];
/**
* The path to the HTML template to use for the application.
* @param {string}
*/
htmlTemplate?: string;
// style configs
/**
* Whether to enable the bundle analyzer plugin.
* @param {boolean}
*/
analyzer?: boolean;
/**
* An array of additional PostCSS plugins to use.
* @param {Plugin[]}
*/
extraPostCSSPlugins?: Plugin[];
/**
* Options to pass to the Less compiler.
* @param {*}
*/
lessOptions?: any;
// integrated plugins options
/**
* A function to dynamically resolve module requests.
* @param {Function}
*/
dynamicResolve?: <T extends any>(request: T) => T;
/**
* Whether to enable the auto-polyfills plugin, or an options object for the plugin.
* @param {string}
*/
autoPolyfills: boolean | AutoPolyfillsWebpackPluginOptions;
// dev, or serve configs
/**
* Options for the development server.
* @param {{proxy?: Record<string, any>, host: string, port: number, staticPath?: string, historyApiFallback?: any, compilationSuccessInfo?: { messages: string[]; notes?: string[] }}}
*/
serve: {
proxy?: Record<string, any>;
host: string;
Expand All @@ -32,6 +96,10 @@ export type IOptions = {
compilationSuccessInfo?: { messages: string[]; notes?: string[] };
};
// experimental features
/**
* Experimental features to enable.
* @param {{speedUp?: boolean, minimizer?: boolean, disableLazyImports?: boolean, enableCssModule?: boolean, compress?: any}}
*/
experiment?: {
speedUp?: boolean;
minimizer?: boolean;
Expand All @@ -40,6 +108,10 @@ export type IOptions = {
compress?: any;
};
//misc
/**
* Options for the linter plugins.
* @param {Record<IKeys, Omit<IOpts, 'write'>>}
*/
lints?: Record<IKeys, Omit<IOpts, 'write'>>;
};

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
import { Compiler } from 'webpack';
import fs from 'fs/promises';
import path from 'path';

class PurgeCacheWebpackPlugin {
WEBPACK_PLUGIN_NAME = 'PurgeCacheWebpackPlugin';

purgeCacheFiles(
directory: string,
maxAge: number,
callback: (errors?: Error[]) => void
) {
fs.readdir(directory)
.then(files => {
const expiredPacks = [];
if (files.length === 0) return callback();

for (const file of files) {
const pack = new Promise((resolve, reject) => {
const filePath = path.join(directory, file);
fs.stat(filePath)
.then(stats => {
if (stats.mtime.getTime() + maxAge < Date.now()) {
fs.unlink(filePath)
.then(() => {
resolve(true);
})
.catch(err => reject(err));
} else {
resolve(true);
}
})
.catch(err => reject(err));
});

expiredPacks.push(pack);
}

Promise.allSettled(expiredPacks).then(results => {
const errors = results
.filter(result => result.status === 'rejected')
.map((result: any) => result.reason);
callback(errors);
});
})
.catch(err => {
callback([err]);
});
}

apply(compiler: Compiler) {
compiler.hooks.done.tapAsync(
{ name: this.WEBPACK_PLUGIN_NAME },
(_, callback) => {
const { type, maxAge, cacheLocation } = compiler.options.cache as any;
if (type === 'filesystem') {
const logger = compiler.getInfrastructureLogger(
this.WEBPACK_PLUGIN_NAME
);
this.purgeCacheFiles(cacheLocation, maxAge, errors => {
if (errors?.length) {
errors.forEach(err => logger.warn(err.message));
} else {
logger.info(`purge expired cache files completed`);
}
callback();
});
} else {
callback();
}
}
);
}
}

export default PurgeCacheWebpackPlugin;
Loading
Loading