Skip to content

Commit

Permalink
feat(build): 各个插件转为ESM格式 (#39)
Browse files Browse the repository at this point in the history
  • Loading branch information
otakustay committed Jan 23, 2022
1 parent d10eaf9 commit 9e36376
Show file tree
Hide file tree
Showing 31 changed files with 77 additions and 105 deletions.
4 changes: 2 additions & 2 deletions packages/babel-plugin-add-react-display-name/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@
"version": "3.0.6",
"license": "MIT",
"type": "module",
"main": "./dist/index.js",
"types": "./dist/index.d.ts",
"exports": {
".": "./dist/index.js"
},
"main": "./dist/index.js",
"types": "./dist/index.d.ts",
"engines": {
"node": ">=14.18.0"
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@
"version": "3.0.6",
"license": "MIT",
"type": "module",
"main": "./dist/index.js",
"types": "./dist/index.d.ts",
"exports": {
".": "./dist/index.js",
"./useComponentFile": "./dist/useComponentFile.js"
},
"main": "./dist/index.js",
"types": "./dist/index.d.ts",
"engines": {
"node": ">=14.18.0"
},
Expand Down
4 changes: 2 additions & 2 deletions packages/babel-utils/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@
"version": "3.0.6",
"license": "MIT",
"type": "module",
"main": "./dist/index.js",
"types": "./dist/index.d.ts",
"exports": {
".": "./dist/index.js"
},
"main": "./dist/index.js",
"types": "./dist/index.d.ts",
"engines": {
"node": ">=14.18.0"
},
Expand Down
3 changes: 1 addition & 2 deletions packages/cli-babel/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,10 @@
"license": "MIT",
"type": "module",
"main": "./dist/index.js",
"types": "./dist/index.d.ts",
"exports": {
".": "./dist/index.js"
},
"main": "./dist/index.js",
"types": "./dist/index.d.ts",
"engines": {
"node": ">=14.18.0"
},
Expand Down
3 changes: 1 addition & 2 deletions packages/cli-build/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,10 @@
"license": "MIT",
"type": "module",
"main": "./dist/index.js",
"types": "./dist/index.d.ts",
"exports": {
".": "./dist/index.js"
},
"main": "./dist/index.js",
"types": "./dist/index.d.ts",
"engines": {
"node": ">=14.18.0"
},
Expand Down
3 changes: 1 addition & 2 deletions packages/cli-dev/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,10 @@
"license": "MIT",
"type": "module",
"main": "./dist/index.js",
"types": "./dist/index.d.ts",
"exports": {
".": "./dist/index.js"
},
"main": "./dist/index.js",
"types": "./dist/index.d.ts",
"engines": {
"node": ">=14.18.0"
},
Expand Down
3 changes: 1 addition & 2 deletions packages/cli-lint/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,10 @@
"license": "MIT",
"type": "module",
"main": "./dist/index.js",
"types": "./dist/index.d.ts",
"exports": {
".": "./dist/index.js"
},
"main": "./dist/index.js",
"types": "./dist/index.d.ts",
"engines": {
"node": ">=14.18.0"
},
Expand Down
3 changes: 1 addition & 2 deletions packages/cli-play/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,10 @@
"license": "MIT",
"type": "module",
"main": "./dist/index.js",
"types": "./dist/index.d.ts",
"exports": {
".": "./dist/index.js"
},
"main": "./dist/index.js",
"types": "./dist/index.d.ts",
"engines": {
"node": ">=14.18.0"
},
Expand Down
3 changes: 1 addition & 2 deletions packages/cli-test/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,10 @@
"license": "MIT",
"type": "module",
"main": "./dist/index.js",
"types": "./dist/index.d.ts",
"exports": {
".": "./dist/index.js"
},
"main": "./dist/index.js",
"types": "./dist/index.d.ts",
"engines": {
"node": ">=14.18.0"
},
Expand Down
4 changes: 2 additions & 2 deletions packages/cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@
"version": "3.0.6",
"license": "MIT",
"type": "module",
"main": "./dist/index.js",
"types": "./dist/index.d.ts",
"exports": {
".": "./dist/index.js"
},
"main": "./dist/index.js",
"types": "./dist/index.d.ts",
"engines": {
"node": ">=14.18.0"
},
Expand Down
4 changes: 2 additions & 2 deletions packages/config-babel/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@
"version": "3.0.6",
"license": "MIT",
"type": "module",
"main": "./dist/index.js",
"types": "./dist/index.d.ts",
"exports": {
".": "./dist/index.js",
"./willBreakingInternalUseOnly": "./dist/internal.cjs"
},
"main": "./dist/index.js",
"types": "./dist/index.d.ts",
"engines": {
"node": ">=14.18.0"
},
Expand Down
4 changes: 2 additions & 2 deletions packages/config-lint/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@
"version": "3.0.6",
"license": "MIT",
"type": "module",
"main": "./dist/index.js",
"types": "./dist/index.d.ts",
"exports": {
".": "./dist/index.js",
"./patch": "./config/patch.cjs",
"./config/*": "./config/*.cjs"
},
"main": "./dist/index.js",
"types": "./dist/index.d.ts",
"engines": {
"node": ">=14.18.0"
},
Expand Down
4 changes: 2 additions & 2 deletions packages/config-webpack-dev-server/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@
"version": "3.0.6",
"license": "MIT",
"type": "module",
"main": "./dist/index.js",
"types": "./dist/index.d.ts",
"exports": {
".": "./dist/index.js"
},
"main": "./dist/index.js",
"types": "./dist/index.d.ts",
"engines": {
"node": ">=14.18.0"
},
Expand Down
4 changes: 2 additions & 2 deletions packages/config-webpack/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@
"version": "3.0.6",
"license": "MIT",
"type": "module",
"main": "./dist/index.js",
"types": "./dist/index.d.ts",
"exports": {
".": "./dist/index.js"
},
"main": "./dist/index.js",
"types": "./dist/index.d.ts",
"engines": {
"node": ">=14.18.0"
},
Expand Down
4 changes: 2 additions & 2 deletions packages/core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@
"version": "3.0.6",
"license": "MIT",
"type": "commonjs",
"main": "./dist/index.js",
"types": "./dist/index.d.ts",
"exports": {
".": "./dist/index.js"
},
"main": "./dist/index.js",
"types": "./dist/index.d.ts",
"engines": {
"node": ">=14.18.0"
},
Expand Down
9 changes: 0 additions & 9 deletions packages/plugin-qiankun/jest.config.js

This file was deleted.

16 changes: 10 additions & 6 deletions packages/plugin-qiankun/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,12 @@
"name": "@reskript/plugin-qiankun",
"version": "3.0.6",
"license": "MIT",
"type": "commonjs",
"type": "module",
"main": "./dist/index.js",
"types": "./dist/index.d.ts",
"exports": {
".": "./dist/index.js"
},
"engines": {
"node": ">=14.18.0"
},
Expand All @@ -18,18 +21,19 @@
"clean": "rm -rf dist",
"build": "tsc -p tsconfig.build.json",
"lint": "eslint --max-warnings=0 src",
"test": "jest"
"test": "vitest run"
},
"devDependencies": {
"@types/dedent": "^0.7.0",
"@types/jest": "^27.0.3",
"@types/node": "^17.0.4",
"c8": "^7.10.0",
"eslint": "^8.6.0",
"jest": "^27.4.5",
"ts-jest": "^27.1.2",
"typescript": "4.6.0-dev.20220105"
"typescript": "4.6.0-dev.20220105",
"vite": "^2.7.7",
"vitest": "^0.0.115"
},
"dependencies": {
"@reskript/core": "3.0.6",
"@reskript/settings": "3.0.6",
"dedent": "^0.7.0",
"esbuild": "^0.14.8",
Expand Down
1 change: 1 addition & 0 deletions packages/plugin-qiankun/src/__tests__/index.test.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import {test, expect} from 'vitest';
import {fillProjectSettings} from '@reskript/settings';
import plugin from '../index';

Expand Down
1 change: 1 addition & 0 deletions packages/plugin-qiankun/src/__tests__/runtimeEntry.test.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import {test, expect} from 'vitest';
import runtimeEntry from '../runtimeEntry';

test('output bundle', async () => {
Expand Down
3 changes: 2 additions & 1 deletion packages/plugin-qiankun/src/htmlEntry.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import fs from 'fs/promises';
// @ts-expect-error
import dedent from 'dedent';
import {Options, TemplateConfig, PlaceholderConfig} from './interface';
import {Options, TemplateConfig, PlaceholderConfig} from './interface.js';

const DEFAULT_BACKGROUND_COLOR = '#f5f5f5';

Expand Down
6 changes: 3 additions & 3 deletions packages/plugin-qiankun/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import {SettingsPlugin, BuildSettings, DevServerSettings} from '@reskript/settings';
import {Request, Response} from 'webpack-dev-server';
import {Options} from './interface';
import htmlEntry from './htmlEntry';
import runtimeEntry from './runtimeEntry';
import {Options} from './interface.js';
import htmlEntry from './htmlEntry.js';
import runtimeEntry from './runtimeEntry.js';

export default (appName: string, options?: Options): SettingsPlugin => {
const finalizeBuild: BuildSettings['finalize'] = config => {
Expand Down
7 changes: 5 additions & 2 deletions packages/plugin-qiankun/src/runtimeEntry.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import {build, BuildOptions} from 'esbuild';
// @ts-expect-error
import dedent from 'dedent';
import {dirFromImportMeta} from '@reskript/core';

const content = (appName: string) => dedent`
import {registerMicroApps, start} from 'qiankun';
Expand All @@ -20,14 +22,15 @@ export default async (appName: string) => {
const options: BuildOptions = {
stdin: {
contents: content(appName),
resolveDir: __dirname,
resolveDir: dirFromImportMeta(import.meta.url),
},
bundle: true,
format: 'iife',
write: false,
sourcemap: false,
define: {
'process.env.NODE_ENV': '"development"',
// 为了避免在UT的时候被`vitest`给替换成`"test": '"development"'`这样子,增加一些动态计算
['0process.env.NODE_ENV0'.slice(1, -1)]: '"development"',
},
};
const bundle = await build(options);
Expand Down
5 changes: 4 additions & 1 deletion packages/plugin-sass/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,12 @@
"name": "@reskript/plugin-sass",
"version": "3.0.6",
"license": "MIT",
"type": "commonjs",
"type": "module",
"main": "./dist/index.js",
"types": "./dist/index.d.ts",
"exports": {
".": "./dist/index.js"
},
"engines": {
"node": ">=14.18.0"
},
Expand Down
2 changes: 1 addition & 1 deletion packages/plugin-sass/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import resolve from 'resolve';
import sass from 'sass';
import {normalizeRuleMatch} from '@reskript/core';
import {SettingsPlugin, BuildSettings, LoaderType} from '@reskript/settings';
import {SassLoaderOptions} from './interface';
import {SassLoaderOptions} from './interface.js';

export default (options: SassLoaderOptions = {}): SettingsPlugin => {
const finalizeBuild: BuildSettings['finalize'] = (config, entry, internals) => {
Expand Down
5 changes: 4 additions & 1 deletion packages/plugin-workspace-no-build/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,12 @@
"name": "@reskript/plugin-workspace-no-build",
"version": "3.0.6",
"license": "MIT",
"type": "commonjs",
"type": "module",
"main": "./dist/index.js",
"types": "./dist/index.d.ts",
"exports": {
".": "./dist/index.js"
},
"engines": {
"node": ">=14.18.0"
},
Expand Down
10 changes: 8 additions & 2 deletions packages/plugin-workspace-no-build/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,14 @@
import path from 'path';
import {logger, isMonorepo, normalizeRuleMatch} from '@reskript/core';
import {SettingsPlugin} from '@reskript/settings';
import {Options, LocalPackageInfo} from './interface';
import {resolveParticipant, findSiblingPackages, buildPackageInfo, buildPeerAlias, checkDependencyGraph} from './utils';
import {Options, LocalPackageInfo} from './interface.js';
import {
resolveParticipant,
findSiblingPackages,
buildPackageInfo,
buildPeerAlias,
checkDependencyGraph,
} from './utils.js';

export default (options: Options = {}): SettingsPlugin => async (settings, {cwd}) => {
const isWorkspace = await isMonorepo(cwd);
Expand Down
2 changes: 1 addition & 1 deletion packages/plugin-workspace-no-build/src/utils.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import path from 'path';
import {findMonorepoRoot, resolveMonorepoPackageDirectories, logger, readPackageConfig, pMap} from '@reskript/core';
import {minVersion, satisfies} from 'semver';
import {Options, LocalPackageInfo} from './interface';
import {Options, LocalPackageInfo} from './interface.js';

export const resolveParticipant = (defaults: LocalPackageInfo[], {includes, excludes}: Options) => {
// 如果2个都没有,就用默认的
Expand Down
4 changes: 2 additions & 2 deletions packages/webpack-plugin-extra-script/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@
"version": "3.0.6",
"license": "MIT",
"type": "module",
"main": "./dist/index.js",
"types": "./dist/index.d.ts",
"exports": {
".": "./dist/index.js"
},
"main": "./dist/index.js",
"types": "./dist/index.d.ts",
"engines": {
"node": ">=14.18.0"
},
Expand Down
Loading

0 comments on commit 9e36376

Please sign in to comment.