Skip to content

Commit

Permalink
build: complete build system
Browse files Browse the repository at this point in the history
  • Loading branch information
sergeysova committed Oct 7, 2021
1 parent fcd30f1 commit f058c8a
Show file tree
Hide file tree
Showing 9 changed files with 38 additions and 16 deletions.
2 changes: 1 addition & 1 deletion .eslintignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
*.test.ts
integration
dist
dist/**
4 changes: 2 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ typings/
.nuxt

# rollup.config.js default build output
dist/
node_modules/dist/

# Uncomment the public line if your project uses Gatsby
# https://nextjs.org/blog/next-9-1#public-directory-support
Expand Down Expand Up @@ -179,5 +179,5 @@ $RECYCLE.BIN/

# End of https://www.gitignore.io/api/node,windows,linux,macos

dist
.idea
dist
8 changes: 4 additions & 4 deletions MIGRATION.md
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ const received = splitMap({
cases: {
firstName: (string) => string.split(' ')[0], // string | undefined
lastName: (string) => string.split(' ')[1], // string | undefined
});
});
```
- First argument should be `source`
Expand Down Expand Up @@ -340,10 +340,10 @@ const source = spread({
```
1. If you have two arguments:
- First argument should be `source` in object
- Second argument should be `targets`
- First argument should be `source` in object
- Second argument should be `targets`
1. If only one argument:
- Wrap it to object and assign to `targets`
- Wrap it to object and assign to `targets`
https://github.com/sergeysova/patronum/pull/61
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"cleanup": "rm -rf dist && mkdir dist",
"build:indexes": "node scripts/build.js",
"build:types": "tsc --project ./tsconfig.build.json",
"build:commonjs": "yarn babel --out-dir ./dist src -x .ts --ignore '**/*.test.ts','**/*.d.ts'",
"build:commonjs": "yarn babel --verbose --out-dir dist src -x .ts --ignore '**/*.test.ts','**/*.d.ts'",
"build:mjs": "ESMODULES=true yarn build:commonjs --out-file-extension .mjs",
"build:bundles": "rollup -c",
"build": "run-s cleanup build:indexes build:types build:commonjs build:mjs build:bundles",
Expand Down
2 changes: 1 addition & 1 deletion rollup.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ const commonjs = require('@rollup/plugin-commonjs');
const plugins = [
nodeResolve({ jsnext: true, skip: ['effector'], extensions: ['.js', '.mjs'] }),
commonjs({ extensions: ['.js', '.mjs'] }),
// terser({}),
terser({}),
];

const input = 'dist/index.js';
Expand Down
13 changes: 11 additions & 2 deletions scripts/build.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ const {
createDistribution,
writeFile,
createMjsIndex,
createExportsMap,
} = require('./libraries');
const packageJson = require('./source.package.js');

Expand All @@ -20,14 +21,22 @@ async function main() {

const directory = await createDistribution('./dist');
await directory.copyList('./src', staticFiles);

pkg.files.push(...staticFiles);
await directory.copyList('./', ['README.md', 'MIGRATION.md', 'LICENSE']);

const found = await globby(`./src/*/${packageMarker}`);
const names = found.map((name) =>
name.replace(`/${packageMarker}`, '').replace('./src/', ''),
);

pkg.exports = {
'.': {
require: './index.js',
import: './index.mjs',
default: './index.mjs',
},
...createExportsMap(names),
};

await directory.write('index.js', createCommonJsIndex(names));
await directory.write('index.mjs', createMjsIndex(names));
await directory.write('index.d.ts', createTypingsIndex(names));
Expand Down
12 changes: 12 additions & 0 deletions scripts/libraries.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,17 @@ function createFactoriesJson(library, names) {
return { factories, mapping };
}

function createExportsMap(names) {
const object = {};
names.forEach((name) => {
object[`./${name}`] = {
require: `./${name}/index.js`,
import: `./${name}/index.mjs`,
};
});
return object;
}

async function createDistribution(dir) {
return {
write: (path, content) => writeFile(`${dir}/${path}`, content),
Expand All @@ -56,6 +67,7 @@ module.exports = {
createCommonJsIndex,
createMjsIndex,
createTypingsIndex,
createExportsMap,
createFactoriesJson,
createDistribution,
};
7 changes: 4 additions & 3 deletions scripts/source.package.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@ module.exports = () => ({
name: 'patronum',
version: '1.2.0-next.2',
description: '☄️ Effector utility library delivering modularity and convenience',
main: 'dist/patronum.cjs.js',
type: 'module',
main: 'patronum.cjs.js',
types: 'index.d.ts',
browser: 'dist/patronum.umd.js',
files: ['*/*.d.ts', '*/*.js', '*/*.mjs', 'dist'],
module: 'patronum.mjs',
browser: 'patronum.umd.js',
repository: {
type: 'git',
url: 'git+https://github.com/effector/patronum.git',
Expand Down
4 changes: 2 additions & 2 deletions tsconfig.build.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
"extends": "./tsconfig.json",
"compilerOptions": {
"emitDeclarationOnly": true,
"declarationDir": "./dist",
"declarationDir": "./node_modules/dist",
"declaration": true,
"rootDir": "./src",
"outDir": "./dist",
"outDir": "./node_modules/dist",
"allowJs": false
},
"exclude": [
Expand Down

0 comments on commit f058c8a

Please sign in to comment.