Skip to content

Commit be3c5a6

Browse files
committed
refactor: move build into its own dir dist./
1 parent aa4256b commit be3c5a6

14 files changed

+1952
-4304
lines changed

.github/workflows/publish.yml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ jobs:
2727
run: pnpm build
2828

2929
- name: Build test
30-
run: pnpm test-build
30+
run: pnpm test:code:build
3131

3232
- name: Run tests
3333
run: pnpm test
@@ -41,9 +41,10 @@ jobs:
4141
tagRegex: 'v(.*)'
4242

4343
- name: Set version from release
44-
uses: reedyuk/npm-version@1.0.1
44+
uses: reedyuk/npm-version@1.1.1
4545
with:
4646
version: ${{ steps.version.outputs.tag }}
47+
package: 'dist/'
4748
git-tag-version: false
4849

4950
- name: Create NPM config
@@ -53,3 +54,4 @@ jobs:
5354

5455
- name: Publish package
5556
run: npm publish
57+
working-directory: ./temp

.github/workflows/test.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ jobs:
2525
run: pnpm build
2626

2727
- name: Build test
28-
run: pnpm test-build
28+
run: pnpm test:code:build
2929

3030
- name: Run tests
3131
run: pnpm test

.prettierrc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
"trailingComma": "all",
88
"useTabs": false,
99
"plugins": ["@trivago/prettier-plugin-sort-imports"],
10-
"importOrder": ["<THIRD_PARTY_MODULES>", "^[./]"],
10+
"importOrder": ["^node:", "<THIRD_PARTY_MODULES>", "^[./]"],
1111
"importOrderSeparation": true,
1212
"importOrderSortSpecifiers": true,
1313
"importOrderCaseInsensitive": true

build.mjs

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
import fs from 'node:fs/promises';
2+
3+
import prettyMs from 'pretty-ms';
4+
import { rollup } from 'rollup';
5+
6+
import configs from './rollup.config.cjs';
7+
8+
for (const config of configs) {
9+
await measure(
10+
`${config.input}${config.output.file ?? config.output.dir}`,
11+
`created in`,
12+
async () => {
13+
const bundle = await rollup(config);
14+
await bundle.write(config.output);
15+
},
16+
);
17+
}
18+
19+
await measure(`package.json → ./dist/package.json`, `created in`, async () => {
20+
const Package = JSON.parse(
21+
await fs.readFile('./package.json', { encoding: 'utf-8' }),
22+
);
23+
delete Package.devDependencies;
24+
delete Package.scripts;
25+
await fs.writeFile('./dist/package.json', JSON.stringify(Package), {
26+
encoding: 'utf-8',
27+
});
28+
});
29+
30+
await fs.copyFile('./Readme.md', './dist/Readme.md');
31+
console.log(`Copied Readme.md → ./dist/Readme.md`);
32+
33+
async function measure(start, end, fn) {
34+
console.log(start);
35+
const time = performance.now();
36+
await fn();
37+
console.log('↳', end, prettyMs(performance.now() - time), '\r\n');
38+
}

dist-test/no-ssr/create-reflect.test.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { createReflect } from '../../reflect.cjs';
1+
import { createReflect } from '../../dist/reflect';
22
import { render } from '@testing-library/react';
33
import userEvent from '@testing-library/user-event';
44
import { createEffect, createEvent, createStore, restore } from 'effector';

dist-test/no-ssr/reflect.test.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { reflect } from '../../reflect.cjs';
1+
import { reflect } from '../../dist/reflect';
22
import { render } from '@testing-library/react';
33
import userEvent from '@testing-library/user-event';
44
import { createEffect, createEvent, createStore, restore } from 'effector';

dist-test/ssr/create-reflect.test.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
import { createReflect } from '../../ssr';
1+
import { createReflect } from '../../dist/scope';
22
import { render } from '@testing-library/react';
33
import { allSettled, createDomain, fork, restore } from 'effector';
4-
import { Provider } from 'effector-react/ssr';
4+
import { Provider } from 'effector-react/scope';
55
import React, { ChangeEvent, FC, InputHTMLAttributes } from 'react';
66

77
// Example1 (InputCustom)

dist-test/ssr/reflect.test.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
import { reflect } from '../../ssr';
1+
import { reflect } from '../../dist/scope';
22
import { render } from '@testing-library/react';
33
import userEvent from '@testing-library/user-event';
44
import { allSettled, createDomain, fork, restore } from 'effector';
5-
import { Provider } from 'effector-react/ssr';
5+
import { Provider } from 'effector-react/scope';
66
import React, { ChangeEvent, FC, InputHTMLAttributes } from 'react';
77

88
// Example1 (InputCustom)

jest.config.js

Lines changed: 187 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,187 @@
1+
/*
2+
* For a detailed explanation regarding each configuration property and type check, visit:
3+
* https://jestjs.io/docs/en/configuration.html
4+
*/
5+
6+
module.exports = {
7+
// All imported modules in your tests should be mocked automatically
8+
// automock: false,
9+
10+
// Stop running tests after `n` failures
11+
// bail: 0,
12+
13+
// The directory where Jest should store its cached dependency information
14+
// cacheDirectory: "/private/var/folders/hz/yzcpd231371g28ykrmnw6_ym0000gn/T/jest_dx",
15+
16+
// Automatically clear mock calls and instances between every test
17+
clearMocks: true,
18+
19+
// Indicates whether the coverage information should be collected while executing the test
20+
// collectCoverage: false,
21+
22+
// An array of glob patterns indicating a set of files for which coverage information should be collected
23+
// collectCoverageFrom: undefined,
24+
25+
// The directory where Jest should output its coverage files
26+
// coverageDirectory: undefined,
27+
28+
// An array of regexp pattern strings used to skip coverage collection
29+
// coveragePathIgnorePatterns: [
30+
// "/node_modules/"
31+
// ],
32+
33+
// Indicates which provider should be used to instrument code for coverage
34+
// coverageProvider: "babel",
35+
36+
// A list of reporter names that Jest uses when writing coverage reports
37+
// coverageReporters: [
38+
// "json",
39+
// "text",
40+
// "lcov",
41+
// "clover"
42+
// ],
43+
44+
// An object that configures minimum threshold enforcement for coverage results
45+
// coverageThreshold: undefined,
46+
47+
// A path to a custom dependency extractor
48+
// dependencyExtractor: undefined,
49+
50+
// Make calling deprecated APIs throw helpful error messages
51+
// errorOnDeprecated: false,
52+
53+
// Force coverage collection from ignored files using an array of glob patterns
54+
// forceCoverageMatch: [],
55+
56+
// A path to a module which exports an async function that is triggered once before all test suites
57+
// globalSetup: undefined,
58+
59+
// A path to a module which exports an async function that is triggered once after all test suites
60+
// globalTeardown: undefined,
61+
62+
// A set of global variables that need to be available in all test environments
63+
// globals: {},
64+
65+
// The maximum amount of workers used to run your tests. Can be specified as % or a number. E.g. maxWorkers: 10% will use 10% of your CPU amount + 1 as the maximum worker number. maxWorkers: 2 will use a maximum of 2 workers.
66+
// maxWorkers: "50%",
67+
68+
// An array of directory names to be searched recursively up from the requiring module's location
69+
// moduleDirectories: [
70+
// "node_modules"
71+
// ],
72+
73+
// An array of file extensions your modules use
74+
moduleFileExtensions: ['js', 'cjs', 'json', 'jsx', 'ts', 'tsx', 'node'],
75+
76+
// A map from regular expressions to module names or to arrays of module names that allow to stub out resources with a single module
77+
// moduleNameMapper: {},
78+
79+
// An array of regexp pattern strings, matched against all module paths before considered 'visible' to the module loader
80+
// modulePathIgnorePatterns: [],
81+
82+
// Activates notifications for test results
83+
// notify: false,
84+
85+
// An enum that specifies notification mode. Requires { notify: true }
86+
// notifyMode: "failure-change",
87+
88+
// A preset that is used as a base for Jest's configuration
89+
// preset: undefined,
90+
91+
// Run tests from one or more projects
92+
// projects: undefined,
93+
94+
// Use this configuration option to add custom reporters to Jest
95+
// reporters: undefined,
96+
97+
// Automatically reset mock state between every test
98+
// resetMocks: false,
99+
100+
// Reset the module registry before running each individual test
101+
// resetModules: false,
102+
103+
// A path to a custom resolver
104+
// resolver: undefined,
105+
106+
// Automatically restore mock state between every test
107+
// restoreMocks: false,
108+
109+
// The root directory that Jest should scan for tests and modules within
110+
// rootDir: undefined,
111+
112+
// A list of paths to directories that Jest should use to search for files in
113+
// roots: [
114+
// "<rootDir>"
115+
// ],
116+
117+
// Allows you to use a custom runner instead of Jest's default test runner
118+
// runner: "jest-runner",
119+
120+
// The paths to modules that run some code to configure or set up the testing environment before each test
121+
// setupFiles: [],
122+
123+
// A list of paths to modules that run some code to configure or set up the testing framework before each test
124+
// setupFilesAfterEnv: [],
125+
126+
// The number of seconds after which a test is considered as slow and reported as such in the results.
127+
// slowTestThreshold: 5,
128+
129+
// A list of paths to snapshot serializer modules Jest should use for snapshot testing
130+
// snapshotSerializers: [],
131+
132+
// The test environment that will be used for testing
133+
testEnvironment: 'jsdom',
134+
135+
// Options that will be passed to the testEnvironment
136+
// testEnvironmentOptions: {},
137+
138+
// Adds a location field to test results
139+
// testLocationInResults: false,
140+
141+
// The glob patterns Jest uses to detect test files
142+
// testMatch: [
143+
// "**/__tests__/**/*.[jt]s?(x)",
144+
// "**/?(*.)+(spec|test).[tj]s?(x)"
145+
// ],
146+
147+
// An array of regexp pattern strings that are matched against all test paths, matched tests are skipped
148+
// testPathIgnorePatterns: [
149+
// "/node_modules/"
150+
// ],
151+
152+
// The regexp pattern or array of patterns that Jest uses to detect test files
153+
// testRegex: [],
154+
155+
// This option allows the use of a custom results processor
156+
// testResultsProcessor: undefined,
157+
158+
// This option allows use of a custom test runner
159+
// testRunner: "jasmine2",
160+
161+
// This option sets the URL for the jsdom environment. It is reflected in properties such as location.href
162+
// testURL: "http://localhost",
163+
164+
// Setting this value to "fake" allows the use of fake timers for functions such as "setTimeout"
165+
// timers: "real",
166+
167+
// A map from regular expressions to paths to transformers
168+
// transform: undefined,
169+
170+
// An array of regexp pattern strings that are matched against all source file paths, matched files will skip transformation
171+
// transformIgnorePatterns: [
172+
// "/node_modules/",
173+
// "\\.pnp\\.[^\\/]+$"
174+
// ],
175+
176+
// An array of regexp pattern strings that are matched against all modules before the module loader will automatically return a mock for them
177+
// unmockedModulePathPatterns: undefined,
178+
179+
// Indicates whether each individual test should be reported during the run
180+
// verbose: undefined,
181+
182+
// An array of regexp patterns that are matched against all source file paths before re-running tests in watch mode
183+
// watchPathIgnorePatterns: [],
184+
185+
// Whether to use watchman for file crawling
186+
// watchman: true,
187+
};

package.json

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,10 @@
1212
"access": "public"
1313
},
1414
"packageManager": "[email protected]",
15-
"source": "src/index.ts",
1615
"exports": {
1716
".": {
1817
"import": "./reflect.mjs",
19-
"require": "./reflect.cjs.js",
18+
"require": "./reflect.cjs",
2019
"default": "./reflect.mjs"
2120
},
2221
"./reflect.mjs": "./reflect.mjs",
@@ -33,7 +32,7 @@
3332
"default": "./scope.mjs"
3433
}
3534
},
36-
"main": "reflect.cjs.js",
35+
"main": "reflect.cjs",
3736
"module": "reflect.mjs",
3837
"typings": "index.d.ts",
3938
"files": [
@@ -42,8 +41,8 @@
4241
"index.d.ts",
4342
"ssr.d.ts",
4443
"scope.d.ts",
45-
"reflect.cjs.js",
46-
"reflect.cjs.js.map",
44+
"reflect.cjs",
45+
"reflect.cjs.map",
4746
"reflect.mjs",
4847
"reflect.mjs.map",
4948
"ssr.js",
@@ -60,9 +59,8 @@
6059
"test:types": "tsc -p ./type-tests",
6160
"test": "pnpm test:code && pnpm test:types",
6261
"test:code:build": "jest ./dist-test",
63-
"test-build": "pnpm test:code:build",
64-
"build": "pnpm clear-build && pnpm rollup --config rollup.config.cjs && cp index.d.ts reflect.d.ts",
65-
"clear-build": "rm -f index.* && rm -f reflect.* && rm -f ssr.* && rm -f scope.* && rm -rf dist && rm -rf core",
62+
"build": "pnpm clear-build && node ./build.mjs",
63+
"clear-build": "rm -rf dist",
6664
"prepublishOnly": "pnpm build",
6765
"prepare": "husky install"
6866
},
@@ -83,6 +81,7 @@
8381
"@types/jest": "^26.0.15",
8482
"@types/react": "^16.9.0",
8583
"@types/react-dom": "^16.9.0",
84+
"babel-jest": "^29.4.3",
8685
"babel-plugin-module-resolver": "^4.1.0",
8786
"effector": "^22.0.6",
8887
"effector-react": "^22.1.0",
@@ -93,10 +92,10 @@
9392
"jest": "^26.6.3",
9493
"lint-staged": "^13.1.2",
9594
"prettier": "^2.8.4",
95+
"pretty-ms": "^8.0.0",
9696
"react": "^17.0.1",
9797
"react-dom": "^17.0.1",
9898
"rollup": "^3.18.0",
99-
"rollup-plugin-multi-input": "^1.1.1",
10099
"rollup-plugin-typescript2": "^0.34.1",
101100
"svelte": "^3.2.0",
102101
"ts-jest": "^26.4.4",

0 commit comments

Comments
 (0)