Skip to content

Commit

Permalink
refactor: settings包迁移至ESM (#39)
Browse files Browse the repository at this point in the history
  • Loading branch information
otakustay committed Jan 29, 2022
1 parent ce84916 commit ff3b960
Show file tree
Hide file tree
Showing 10 changed files with 37 additions and 34 deletions.
3 changes: 2 additions & 1 deletion packages/config-jest/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
"name": "@reskript/config-jest",
"version": "3.0.6",
"license": "MIT",
"type": "commonjs",
"main": "./dist/index.js",
"types": "./dist/index.d.ts",
"engines": {
Expand Down Expand Up @@ -44,7 +45,7 @@
"enzyme-to-json": "^3.6.2",
"identity-obj-proxy": "^3.0.0",
"jest-raw-loader": "^1.0.1",
"lodash": "^4.17.21",
"ramda": "^0.27.1",
"resolve": "^1.20.0",
"unixify": "^1.0.0"
},
Expand Down
5 changes: 3 additions & 2 deletions packages/config-jest/src/interface.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import {ProjectAware} from '@reskript/core';
import {FeatureMatrix} from '@reskript/settings';
import type {ProjectAware} from '@reskript/core';
// @ts-expect-error
import type {FeatureMatrix} from '@reskript/settings';

export type TestTarget = 'react' | 'node';

Expand Down
2 changes: 1 addition & 1 deletion packages/config-jest/src/preset.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {merge} from 'lodash';
import {merge} from 'ramda';
import resolve from 'resolve';
import unixify from 'unixify';
import {JestConfigOptions} from './interface';
Expand Down
11 changes: 5 additions & 6 deletions packages/settings/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "@reskript/settings",
"version": "3.0.6",
"license": "MIT",
"type": "commonjs",
"type": "module",
"main": "./dist/index.js",
"types": "./dist/index.d.ts",
"exports": {
Expand All @@ -21,23 +21,22 @@
"clean": "rm -rf dist",
"build": "tsc -p tsconfig.build.json",
"lint": "eslint --max-warnings=0 src",
"test": "jest"
"test": "vitest run"
},
"devDependencies": {
"@types/babel__core": "^7.1.17",
"@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",
"vite": "^2.7.7",
"vitest": "^0.0.115",
"webpack": "^5.65.0"
},
"dependencies": {
"@reskript/core": "3.0.6",
"chokidar": "^3.5.2",
"hasha": "^5.2.0",
"lodash": "^4.17.21",
"schema-utils": "^4.0.0",
"webpack-dev-server": "^4.7.1"
}
Expand Down
14 changes: 8 additions & 6 deletions packages/settings/src/__tests__/plugins.test.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import {test, expect, vi} from 'vitest';
import {ProjectAware} from '@reskript/core';
import {ary} from 'lodash';
import {fillProjectSettings} from '../defaults';
import {ProjectSettings, SettingsPlugin} from '../interface';
import {applyPlugins} from '../plugins';
import {fillProjectSettings} from '../defaults.js';
import {ProjectSettings, SettingsPlugin} from '../interface.js';
import {applyPlugins} from '../plugins.js';

test('one plugin', async () => {
const settings: ProjectSettings = fillProjectSettings({provider: 'webpack', devServer: {}});
const plugin = jest.fn((settings: ProjectSettings, cmd: ProjectAware): ProjectSettings => {
const plugin = vi.fn((settings: ProjectSettings, cmd: ProjectAware): ProjectSettings => {
return {
...settings,
devServer: {
Expand All @@ -19,7 +19,9 @@ test('one plugin', async () => {
const options = {cwd: 'cwd', command: 'build'};
const output = await applyPlugins(settings, [plugin], options);
expect(plugin).toHaveBeenCalled();
// @ts-expect-error
expect(plugin.mock.calls[0][0]).toBe(settings);
// @ts-expect-error
expect(plugin.mock.calls[0][1]).toBe(options);
expect(output.devServer.port).toBe(8000);
});
Expand Down Expand Up @@ -69,7 +71,7 @@ test('plugins factory', async () => {
},
};
};
const factory = jest.fn(ary(() => [port, domain], 1));
const factory = vi.fn(() => [port, domain]);
const output = await applyPlugins(settings, factory, {cwd: '', command: 'build'});
expect(factory).toHaveBeenCalled();
expect(factory.mock.calls[0][0]).toBe('build');
Expand Down
3 changes: 2 additions & 1 deletion packages/settings/src/__tests__/validate.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import validate from '../validate';
import {describe, test, expect} from 'vitest';
import validate from '../validate.js';

describe('validate', () => {
test('empty', () => {
Expand Down
2 changes: 1 addition & 1 deletion packages/settings/src/defaults.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {BuildSettings, DevServerSettings, PlaySettings, ProjectSettings, ReskriptProvider} from './interface';
import {BuildSettings, DevServerSettings, PlaySettings, ProjectSettings, ReskriptProvider} from './interface.js';

type PartialBuildSettings = Omit<Partial<BuildSettings>, 'script' | 'style' | 'inspect'> & {
script?: Partial<BuildSettings['script']>;
Expand Down
11 changes: 6 additions & 5 deletions packages/settings/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
import path from 'path';
import {existsSync} from 'fs';
// @ts-expect-error
import hasha from 'hasha';
import chokidar from 'chokidar';
import {importUserModule, logger, PackageInfo, ProjectAware, readPackageConfig} from '@reskript/core';
import {ProjectSettings, Listener, Observe, ClientProjectSettings, ReskriptProvider} from './interface';
import validate from './validate';
import {fillProjectSettings, PartialProjectSettings} from './defaults';
import {applyPlugins} from './plugins';
import {ProjectSettings, Listener, Observe, ClientProjectSettings, ReskriptProvider} from './interface.js';
import validate from './validate.js';
import {fillProjectSettings, PartialProjectSettings} from './defaults.js';
import {applyPlugins} from './plugins.js';

export * from './interface';
export * from './interface.js';
export {fillProjectSettings, PartialProjectSettings};

const SETTINGS_EXTENSIONS = ['.ts', '.mjs'];
Expand Down
2 changes: 1 addition & 1 deletion packages/settings/src/plugins.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {pReduce} from '@reskript/core';
import {ProjectSettings, ClientProjectSettings, PluginOptions} from './interface';
import {ProjectSettings, ClientProjectSettings, PluginOptions} from './interface.js';

type Plugins = ClientProjectSettings['plugins'];

Expand Down
18 changes: 8 additions & 10 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit ff3b960

Please sign in to comment.