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

build-scripts-2.0.0 #84

Merged
merged 42 commits into from
Nov 22, 2022
Merged
Show file tree
Hide file tree
Changes from 13 commits
Commits
Show all changes
42 commits
Select commit Hold shift + click to select a range
1dbcbe7
feat: first commit
maoxiaoke Jan 25, 2022
0b32e8e
reslover
maoxiaoke Jan 25, 2022
1548beb
reslve update
maoxiaoke Jan 25, 2022
515dd64
fix: 🐛 fix lint
maoxiaoke Jan 26, 2022
8f5cb1b
fix: 🐛 runGetConfigFn
maoxiaoke Jan 26, 2022
74abdb2
fix: 🐛 remove useless code
maoxiaoke Jan 26, 2022
856f84e
fix: 🐛 to fix some lint
maoxiaoke Feb 8, 2022
65d9d73
refactor: 💡 move to pnpm
maoxiaoke Feb 8, 2022
d6e4980
refactor: 💡 refact
maoxiaoke Feb 10, 2022
7de9040
chore: 🤖 pnpm ci
maoxiaoke Feb 14, 2022
bfd1080
test: 💍 pass tests
maoxiaoke Feb 14, 2022
773b16f
chore: 🤖 lints
maoxiaoke Feb 14, 2022
3b5b300
test: 💍 tests
maoxiaoke Feb 14, 2022
6300719
chore: 🤖 refact code
maoxiaoke Feb 17, 2022
487cb06
chore: 🤖 refact logger
maoxiaoke Feb 17, 2022
de53a33
feat: 🎸 supported types & extendsPluginAPI
maoxiaoke Feb 22, 2022
d9f94f5
fix: 🐛 refact code
maoxiaoke Feb 22, 2022
d13c681
feat: 🎸 export public api
maoxiaoke Feb 22, 2022
aa3e9a2
fix: 🐛 refact type
maoxiaoke Feb 22, 2022
8c17d02
fix: 🐛 deepmerge default
maoxiaoke Feb 22, 2022
48a8594
fix: 🐛 undesirable type of usrconfig cause error
maoxiaoke Feb 24, 2022
86d2fcb
chore: 🤖 pass ci
maoxiaoke Feb 24, 2022
318d7d7
fix: 🐛 undefined extendsPluginApi
maoxiaoke Feb 24, 2022
52f71f3
feat: 🎸 add userConfig types & onGetConfig returns
maoxiaoke Feb 25, 2022
868d986
Merge pull request #90 from ice-lab/fix/userConfigTypes
maoxiaoke Feb 25, 2022
039dba1
Turns to Pure ESM Package (#92)
maoxiaoke Mar 25, 2022
0eab9d7
fix: 🐛 js suffix
maoxiaoke Mar 25, 2022
75fb87a
feat: support validation of function (#94)
ClarkXia Mar 29, 2022
a5aba97
fix: type error (#95)
ClarkXia Mar 31, 2022
851045c
fix: 🐛 generic for service (#97)
maoxiaoke Apr 14, 2022
68ca5f7
chore: 🤖 task type (#99)
maoxiaoke Apr 25, 2022
39ac232
Feat/load config (#102)
maoxiaoke Apr 28, 2022
ca93202
feat: refactor types and api (#101)
ClarkXia Jul 11, 2022
cae4c53
fix: lose object property after deepmerge (#106)
luhc228 Jul 11, 2022
1bc33cb
fix: compatible with win32 when import file (#107)
ClarkXia Sep 16, 2022
597bbf5
Merge branch 'master' into version2.0.0
ClarkXia Sep 21, 2022
b49a1cc
fix: check bulit-in plugins (#110)
ClarkXia Sep 21, 2022
4bc1d18
fix: export types (#111)
ClarkXia Nov 22, 2022
b6041d1
docs: update 2.x readme (#105)
ClarkXia Nov 22, 2022
8be320c
Merge branch 'master' into version2.0.0
ClarkXia Nov 22, 2022
77245bc
chore: remove useless folder
ClarkXia Nov 22, 2022
87cd419
Merge branch 'version2.0.0' of github.com:ice-lab/build-scripts into …
ClarkXia Nov 22, 2022
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
16 changes: 2 additions & 14 deletions .eslintignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,6 @@ expected
website
gh-pages
vendors
packages/build-scripts/test
packages/template-plugin/tests
packages/build-scripts/bin
packages/build-scripts/lib
packages/build-plugin-store/lib
packages/build-plugin-ice-router/lib
packages/build-plugin-ice-stark-child/lib
packages/build-plugin-env-config/lib
packages/build-plugin-webpack5/lib
packages/build-plugin-rml/lib
packages/build-plugin-stark-module/lib
packages/build-plugin-stark-module/test
packages/template-component-demo/lib
packages/template-component-demo/es
examples
__tests__
lib
39 changes: 5 additions & 34 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -1,38 +1,9 @@
const { eslint, tslint, deepmerge } = require('@ice/spec');
const { getESLintConfig } = require('@iceworks/spec');

const commonRules = {
'global-require': 0,
'import/no-dynamic-require': 0,
'no-restricted-syntax': ['error', "BinaryExpression[operator='of']"],
'import/order': 0,
};

const jsRules = deepmerge(eslint, {
module.exports = getESLintConfig('react-ts', {
rules: {
...commonRules,
'no-async-promise-executor': 'off',
'@iceworks/best-practices/recommend-polyfill': 'off',
'@typescript-eslint/no-invalid-void-type': 'off',
},
});

const tsRules = deepmerge(tslint, {
rules: {
...commonRules,
'@typescript-eslint/explicit-function-return-type': [
'warn',
{
allowTypedFunctionExpressions: true,
},
],
},
});

delete tsRules.root;

module.exports = {
...jsRules,
overrides: [
{
...tsRules,
files: ['**/*.ts', '**/*.tsx'],
},
],
};
12 changes: 10 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,20 @@ jobs:
- uses: actions/checkout@v2
- name: Set branch name
run: echo >>$GITHUB_ENV BRANCH_NAME=${GITHUB_REF#refs/heads/}

- name: Echo branch name
run: echo ${BRANCH_NAME}

- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v1
with:
node-version: ${{ matrix.node-version }}
registry-url: https://registry.npmjs.org/
- run: npm run setup
- run: npm run test

- name: Install pnpm
uses: pnpm/action-setup@v2
with:
version: 6

- run: pnpm run setup
- run: pnpm run test
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -41,3 +41,4 @@ examples/react-component/es
packages/template-component-demo/lib
packages/template-component-demo/es

.pnpm-debug.log
24 changes: 14 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@

- 完善灵活的插件能力,帮助扩展不同工程构建的场景
- 提供多构建任务机制,支持同时构建多份产物
- 基于 webpack-chain 提供灵活的自定义 webpack 配置能力
- 标准化构建&调试的完整流程,同时提供 Hook 能力进行定制
- 已支持多种场景:
- React 项目开发
Expand Down Expand Up @@ -232,7 +231,6 @@ context 参数包含运行时的各种环境信息:
- `originalUserConfig` 用户在 build.json 中配置的原始内容
- `userConfig` 用户配置,包含被 modifyUserConfig 修改后的结果
- `pkg` 项目 package.json 的内容
- `webpack` webpack 实例,插件中针对 webpack 的逻辑均使用此方式引入

```js
module.exports = ({ context }) => {
Expand All @@ -242,9 +240,9 @@ module.exports = ({ context }) => {
};
```

#### onGetWebpackConfig
#### onGetConfig

通过 `onGetWebpackConfig` 获取 [webpack-chain](https://github.com/neutrinojs/webpack-chain) 形式的配置,并对配置进行自定义修改:
通过 `onGetConfig` 获取通过 [registerTask](#registerTask) 注册的配置,并对配置进行自定义修改:

```js
// 场景一:修改所有 webpack 配置
Expand All @@ -255,15 +253,15 @@ module.exports = ({ onGetWebpackConfig }) => {
}

// 场景二:多 webpack 任务情况下,修改指定任务配置
module.exports = ({onGetWebpackConfig, registerTask}) => {
module.exports = ({onGetConfig, registerTask}) => {
registerTask('web', webpackConfigWeb);
registerTask('weex', webpackConfigWeex);

onGetWebpackConfig('web',(config) => {
onGetConfig('web',(config) => {
config.entry('src/index');
});

onGetWebpackConfig('weex',(config) => {
onGetConfig('weex',(config) => {
config.entry('src/app');
});
}
Expand Down Expand Up @@ -329,7 +327,7 @@ module.exports = ({ log }) => {

通过 registerUserConfig 注册 build.json 中的顶层配置字段,注册是可以进行用户字段校验,支持传入单个配置对象或者包含多个配置对象的数组。

方法生效的生命周期,在 registerTask 和 onGetWebpackConfig 之间。
方法生效的生命周期,在 registerTask 和 onGetConfig 之间。

配置对象字段如下:

Expand All @@ -346,11 +344,11 @@ module.exports = ({ log }) => {

配置忽略指定 webpack 任务

- configWebpack(function)
- setConfig(function)

字段效果,具体作用到 webpack 配置上,接收参数:

- config:webpack-chain 形式的配置
- config:通过 registerTask 注册的配置
- value: build.json 中的字段值
- context:与外部 context 相同,新增字段 taskName 表现当前正在修改的 task

Expand Down Expand Up @@ -570,6 +568,12 @@ module.exports = ({ applyMethod }) => {

## 版本升级

### 1.x -> 2.x

2.x 的核心变化:

- 与 webpack 整体解耦,沉淀为插件开发服务

### 0.x -> 1.x

1.x 核心变化:
Expand Down
13 changes: 7 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@
"packages/*"
],
"scripts": {
"preinstall": "npx only-allow pnpm",
"clean": "rm -rf node_modules ./packages/*/node_modules",
"setup": "npm run clean && yarn install --registry=https://registry.npm.taobao.org && lerna bootstrap --registry=https://registry.npm.taobao.org",
"setup": "npm run clean && pnpm i --registry=https://registry.npmmirror.com",
"lint": "eslint --cache --quiet --ext .js,.ts ./",
"lint-fix": "eslint --cache --ext .js,.ts ./ --fix",
"prettier": "prettier --write '**/*.{js,jsx,tsx,ts,less,md,json}'",
Expand All @@ -21,11 +22,11 @@
"devDependencies": {
"@commitlint/cli": "^7.5.2",
"@commitlint/config-conventional": "^7.5.0",
"@ice/spec": "^0.1.4",
"eslint": "^6.0.1",
"@iceworks/spec": "^1.5.0",
"build-scripts": "workspace:*",
"eslint": "^7.31.0",
"husky": "^1.3.1",
"lerna": "^3.16.4",
"prettier": "^1.19.1",
"typescript": "^3.7.4"
"stylelint": "^10.1.0",
"typescript": "^4"
}
}
36 changes: 36 additions & 0 deletions packages/build-scripts/__tests__/configFiles.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import { createContext } from '../src/Context'
import path = require('path')

describe('load js config', () => {
it('combine basic config', async () => {
const context = await createContext({
args: {},
command: 'start',
rootDir: path.join(__dirname, 'fixtures/jsConfig/')
});

expect(context.userConfig.entry).toEqual('src/index');
});
});

describe('load ts config', () => {
it('combine basic config', async () => {
const context = await createContext({
args: {},
command: 'start',
rootDir: path.join(__dirname, 'fixtures/tsConfig/')
});
expect(context.userConfig.entry).toEqual('src/index');
});
});

describe('load mix config', () => {
it('combine basic config', async () => {
const context = await createContext({
args: {},
command: 'start',
rootDir: path.join(__dirname, 'fixtures/mixConfig/')
});
expect(context.userConfig.entry).toEqual('src/index.ts');
});
});
20 changes: 20 additions & 0 deletions packages/build-scripts/__tests__/createContext.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { createContext } from '../src/Context'
import path = require('path')

describe('create-context', () => {
it('basic', async () => {
const context = await createContext({
args: {
https: true
},
command: 'start',
rootDir: path.join(__dirname, 'fixtures/basic/')
});

// 验证 registerUserConfig
expect(context.userConfig.entry).toEqual('src/index');

// 验证 registerCliOption
expect(context.commandArgs.https).toBeTruthy();
});
});
6 changes: 6 additions & 0 deletions packages/build-scripts/__tests__/fixtures/basic/build.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"entry": "src/index",
"plugins": [
"./plugin.js"
]
}
18 changes: 18 additions & 0 deletions packages/build-scripts/__tests__/fixtures/basic/plugin.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
module.exports = ({
registerUserConfig,
registerCliOption,
}) => {
registerUserConfig([
{
name: 'entry',
validation: 'string'
}
]);

registerCliOption([
{
name: 'https',
commands: ['start', 'build']
}
])
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
module.exports = {
entry: 'src/index',
plugins: [
'./plugin.js'
]
};
8 changes: 8 additions & 0 deletions packages/build-scripts/__tests__/fixtures/jsConfig/plugin.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
module.exports = ({ registerUserConfig }) => {
registerUserConfig([
{
name: 'entry',
validation: 'string'
}
]);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
module.exports = {
entry: 'src/index.js',
plugins: [
"./plugin.js"
]
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"entry": "src/index.ts",
"plugins": [
"./plugin.js"
]
}
8 changes: 8 additions & 0 deletions packages/build-scripts/__tests__/fixtures/mixConfig/plugin.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
module.exports = ({ registerUserConfig }) => {
registerUserConfig([
{
name: 'entry',
validation: 'string'
}
]);
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
interface Config {
entry: string;
plugins: string[];
}

const config: Config = {
entry: 'src/index',
plugins: ['./plugin.js']
};

export default config;
8 changes: 8 additions & 0 deletions packages/build-scripts/__tests__/fixtures/tsConfig/plugin.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
module.exports = ({ registerUserConfig }) => {
registerUserConfig([
{
name: 'entry',
validation: 'string'
}
]);
}
Original file line number Diff line number Diff line change
@@ -1,29 +1,31 @@
import * as path from 'path';
import loadConfig from '../src/utils/loadConfig';
import log = require('../src/utils/log');
import { loadConfig } from '../src/utils/loadConfig';
import { createLogger } from '../src/utils/logger';

const logger = createLogger();

interface IUserConfig {
entry: string;
}

describe('load config file', () => {
it('json file', async () => {
const userConfig = await loadConfig<IUserConfig>(path.join(__dirname, './configFile/config.json'), log);
const userConfig = await loadConfig<IUserConfig>(path.join(__dirname, './configFile/config.json'), logger);
expect(userConfig.entry).toBe('src/json.js');
})

it('js file', async () => {
const userConfig = await loadConfig<IUserConfig>(path.join(__dirname, './configFile/config.js'), log);
const userConfig = await loadConfig<IUserConfig>(path.join(__dirname, './configFile/config.js'), logger);
expect(userConfig.entry).toBe('src/config.js');
})

it('ts file', async () => {
const userConfig = await loadConfig<IUserConfig>(path.join(__dirname, './configFile/config.ts'), log);
const userConfig = await loadConfig<IUserConfig>(path.join(__dirname, './configFile/config.ts'), logger);
expect(userConfig.entry).toBe('src/tsFile.ts');
})

it('esm file', async () => {
const userConfig = await loadConfig<IUserConfig>(path.join(__dirname, './configFile/esmConfig.js'), log);
const userConfig = await loadConfig<IUserConfig>(path.join(__dirname, './configFile/esmConfig.js'), logger);
expect(userConfig.entry).toBe('src/mjsFile.mjs');
})
});
Loading