@websolutespa/bom-compiler 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md ADDED
@@ -0,0 +1,7 @@
1
+ # @websolutespa/bom-compiler
2
+
3
+ ## 0.0.1
4
+
5
+ ### Patch Changes
6
+
7
+ - Added: first release.
package/README.md ADDED
@@ -0,0 +1,11 @@
1
+ # bom-compiler
2
+
3
+ [![npm version](https://badge.fury.io/js/%40websolutespa%2Fbom-compiler.svg)](https://badge.fury.io/js/%40websolutespa%2Fbom-compiler)
4
+
5
+ [![status alpha](https://img.shields.io/badge/status-alpha-red.svg)](https://shields.io/)
6
+
7
+ BOM compiler helper of the [BOM Repository](https://github.com/websolutespa/bom) by [websolute](https://www.websolute.com/).
8
+
9
+ ---
10
+
11
+ ##### *this library is for internal usage and not production ready*
@@ -0,0 +1,54 @@
1
+ // @ts-check
2
+ const test = process.env.NODE_ENV === 'test';
3
+ const prod = process.env.NODE_ENV === 'production';
4
+
5
+ /** @type {import("@babel/core").ParserOptions} */
6
+ module.exports = {
7
+ presets: [
8
+ /*
9
+ ['next/babel', { 'useBuiltIns': false }]
10
+ */
11
+ ['@babel/preset-env', {
12
+ loose: true,
13
+ targets: test ?
14
+ { node: 'current' } :
15
+ { browsers: 'defaults, not IE 11' },
16
+ }],
17
+ /*
18
+ ['next/babel', {
19
+ 'useBuiltIns': false,
20
+ 'preset-env': {
21
+ loose: true,
22
+ targets: test ?
23
+ { node: 'current' } :
24
+ { browsers: 'defaults, not IE 11' },
25
+ },
26
+ 'transform-runtime': {},
27
+ 'styled-jsx': {},
28
+ 'class-properties': {}
29
+ }],
30
+ */
31
+ ['@babel/preset-react', { runtime: 'automatic' }],
32
+ '@babel/preset-typescript'
33
+ ],
34
+ plugins: [
35
+ '@babel/plugin-syntax-dynamic-import',
36
+ false && ['babel-plugin-styled-components', { 'ssr': true }],
37
+ ].filter(Boolean),
38
+ };
39
+
40
+ /*
41
+ const { warn } = console;
42
+
43
+ // Prevents resolution warnings from babel-plugin-module-resolver
44
+ // See https://github.com/tleunen/babel-plugin-module-resolver/issues/315
45
+ // eslint-disable-next-line no-console
46
+ console.warn = (...args) => {
47
+ for (const arg of args) {
48
+ if (arg.startsWith('Could not resolve') && /src/.test(arg)) {
49
+ return;
50
+ }
51
+ }
52
+ warn(...args);
53
+ };
54
+ */
package/index.d.ts ADDED
@@ -0,0 +1,12 @@
1
+ declare function resolveDirname(pathname: string): string;
2
+ declare function clean(): Promise<void>;
3
+ declare function build(): Promise<void>;
4
+ declare function emitDeclaration(): Promise<void>;
5
+
6
+ export {
7
+ resolveDirname,
8
+ clean,
9
+ build,
10
+ emitDeclaration,
11
+ };
12
+
package/index.js ADDED
@@ -0,0 +1,97 @@
1
+ // @ts-check
2
+ /* eslint-disable @typescript-eslint/no-var-requires */
3
+ const spawn = require('cross-spawn');
4
+ const path = require('path');
5
+ const fs = require('fs');
6
+ const rimraf = require('rimraf');
7
+ // import spawn from 'cross-spawn';
8
+ // import * as path from 'path';
9
+ // import rimraf from 'rimraf';
10
+
11
+ function resolveDirname(pathname) {
12
+ if (!/\.(t|j)s$/.test(pathname)) {
13
+ return pathname;
14
+ }
15
+ return path.dirname(pathname);
16
+ }
17
+
18
+ function clean() {
19
+ try {
20
+ const cwd = process.cwd();
21
+ const distPath = path.join(cwd, 'dist');
22
+ /*
23
+ const packagePath = path.join(cwd, 'package.json');
24
+ const package = require(packagePath);
25
+ */
26
+ rimraf.sync(distPath);
27
+ } catch (error) {
28
+ console.log('BomCompiler.clean', error);
29
+ }
30
+ }
31
+
32
+ function build() {
33
+ try {
34
+ const rollupConfigPath = path.join(__dirname, 'rollup.config.js');
35
+ spawn.sync(
36
+ 'rollup',
37
+ ['-c', rollupConfigPath, '--bundleConfigAsCjs'],
38
+ {
39
+ stdio: 'inherit',
40
+ }
41
+ );
42
+ } catch (error) {
43
+ console.log('BomCompiler.build', error);
44
+ }
45
+ }
46
+
47
+ function emitDeclaration() {
48
+ const cwd = process.cwd();
49
+ const tsConfigPath = path.join(cwd, 'tsconfig.declaration.json');
50
+ try {
51
+ console.log('emitDeclaration', tsConfigPath);
52
+ const tsConfigData = getDeclarationConfig();
53
+ fs.writeFileSync(tsConfigPath, tsConfigData, 'utf-8');
54
+ spawn.sync(
55
+ 'tsc',
56
+ ['--project', tsConfigPath, '--emitDeclarationOnly'],
57
+ {
58
+ stdio: 'inherit'
59
+ });
60
+ } catch (error) {
61
+ console.log('BomCompiler.emitDeclaration', error);
62
+ } finally {
63
+ if (fs.statSync(tsConfigPath, { throwIfNoEntry: false })) {
64
+ fs.unlinkSync(tsConfigPath);
65
+ }
66
+ }
67
+ }
68
+
69
+ function getDeclarationConfig() {
70
+ return /* javascript */`
71
+ {
72
+ "extends": "./tsconfig.json",
73
+ "exclude": [
74
+ "jest.config.ts",
75
+ "tsup.config.ts",
76
+ "**/*.test.ts",
77
+ "**/*.test.tsx",
78
+ "node_modules",
79
+ "dist"
80
+ ],
81
+ "compilerOptions": {
82
+ "rootDir": "./src",
83
+ "sourceMap": true,
84
+ "resolveJsonModule": true,
85
+ "emitDeclarationOnly": true,
86
+ "declaration": true,
87
+ "declarationDir": "./dist/types"
88
+ }
89
+ }`;
90
+ }
91
+
92
+ module.exports = {
93
+ resolveDirname,
94
+ clean,
95
+ build,
96
+ emitDeclaration,
97
+ };
package/package.json ADDED
@@ -0,0 +1,62 @@
1
+ {
2
+ "name": "@websolutespa/bom-compiler",
3
+ "version": "0.0.1",
4
+ "description": "Compiler helper of the BOM Repository",
5
+ "keywords": [
6
+ "bom",
7
+ "compiler"
8
+ ],
9
+ "license": "MIT",
10
+ "repository": {
11
+ "type": "git",
12
+ "url": "git://github.com/websolutespa/bom.git"
13
+ },
14
+ "scripts": {},
15
+ "dependencies": {
16
+ "@babel/core": "^7.21.0",
17
+ "@babel/plugin-syntax-dynamic-import": "^7.8.3",
18
+ "@babel/preset-env": "^7.20.2",
19
+ "@babel/preset-react": "^7.18.6",
20
+ "@babel/preset-typescript": "^7.21.0",
21
+ "@rollup/plugin-babel": "^6.0.3",
22
+ "@rollup/plugin-commonjs": "^24.0.1",
23
+ "@rollup/plugin-json": "^6.0.0",
24
+ "@rollup/plugin-node-resolve": "^15.0.1",
25
+ "@rollup/plugin-terser": "^0.4.0",
26
+ "@rollup/plugin-typescript": "^11.0.0",
27
+ "@svgr/rollup": "^6.5.1",
28
+ "babel-loader": "^9.1.2",
29
+ "babel-plugin-styled-components": "^2.0.7",
30
+ "babel-preset-react-app": "^10.0.1",
31
+ "cross-spawn": "latest",
32
+ "node-sass": "^8.0.0",
33
+ "rimraf": "latest",
34
+ "rollup-plugin-copy": "^3.4.0",
35
+ "rollup-plugin-peer-deps-external": "^2.2.4",
36
+ "rollup-plugin-postcss": "^4.0.2",
37
+ "rollup-plugin-typescript2": "^0.34.1",
38
+ "rollup": "^3.17.3",
39
+ "sass-loader": "^13.2.0",
40
+ "typescript": "^4.9.5"
41
+ },
42
+ "peerDependencies": {
43
+ "react": ">=18.2.0",
44
+ "react-dom": ">=18.2.0",
45
+ "styled-components": ">=5.3.6"
46
+ },
47
+ "devDependencies": {
48
+ "@types/cross-spawn": "latest",
49
+ "@types/react": "^18.0.28",
50
+ "@types/react-dom": "^18.0.11",
51
+ "@types/styled-components": "^5.1.26",
52
+ "@websolutespa/tsconfig": "*",
53
+ "eslint-config-websolute": "*",
54
+ "tsup": "latest"
55
+ },
56
+ "publishConfig": {
57
+ "access": "public"
58
+ },
59
+ "sideEffects": false,
60
+ "main": "./index.js",
61
+ "types": "./index.d.ts"
62
+ }
@@ -0,0 +1,130 @@
1
+ import json from '@rollup/plugin-json';
2
+ // import resolve from '@rollup/plugin-node-resolve';
3
+ import svgr from '@svgr/rollup';
4
+ import * as path from 'path';
5
+ // import { nodeResolve } from '@rollup/plugin-node-resolve';
6
+ import peerDepsExternal from 'rollup-plugin-peer-deps-external';
7
+ // import typescript from 'rollup-plugin-typescript2';
8
+ import { babel } from '@rollup/plugin-babel';
9
+ import terser from '@rollup/plugin-terser';
10
+ import typescript from '@rollup/plugin-typescript';
11
+
12
+ const DEBUG = true;
13
+ const TERSER = false;
14
+
15
+ const extensions = ['.ts', '.tsx', '.js', '.jsx', '.json'];
16
+
17
+ const cwd = process.cwd();
18
+
19
+ const packagePath = path.join(cwd, 'package.json');
20
+ // eslint-disable-next-line @typescript-eslint/no-var-requires
21
+ const packageJson = require(packagePath);
22
+ const outputCjs = './dist/cjs/index.js'; // packageJson.main;
23
+ const outputEsm = './dist/esm'; // path.dirname(packageJson.module);
24
+
25
+ function getBabelConfigFile() {
26
+ return path.resolve(__dirname, 'babel.config.js');
27
+ }
28
+
29
+ const rollupConfig = {
30
+ input: 'src/index.ts',
31
+ makeAbsoluteExternalsRelative: true,
32
+ output: [
33
+ {
34
+ format: 'cjs',
35
+ file: outputCjs,
36
+ sourcemap: true,
37
+ interop: 'auto', // 'esModule';
38
+ exports: 'named',
39
+ hoistTransitiveImports: false,
40
+ dynamicImportInCjs: true,
41
+ },
42
+ {
43
+ format: 'esm',
44
+ dir: outputEsm,
45
+ sourcemap: true,
46
+ hoistTransitiveImports: false,
47
+ preserveModules: true,
48
+ preserveModulesRoot: 'src',
49
+ },
50
+ ],
51
+ plugins: [
52
+ peerDepsExternal({
53
+ includeDependencies: true,
54
+ }),
55
+ // nodeResolve({ extensions, preferBuiltins: false }),
56
+ // resolve(),
57
+ // commonjs({ include: /node_modules/ }),
58
+ json(),
59
+ svgr({
60
+ icon: true,
61
+ replaceAttrValues: {
62
+ fill: 'currentColor',
63
+ stroke: 'currentColor',
64
+ },
65
+ }),
66
+ typescript({
67
+ compilerOptions: {
68
+ baseUrl: '.',
69
+ rootDir: './src',
70
+ sourceMap: true,
71
+ composite: false,
72
+ declaration: false,
73
+ declarationMap: false,
74
+ allowSyntheticDefaultImports: true,
75
+ },
76
+ /*
77
+ compilerOptions: {
78
+ baseUrl: '.',
79
+ rootDir: './src',
80
+ sourceMap: true,
81
+ allowSyntheticDefaultImports: true,
82
+ declarationDir: './dist/types',
83
+ ...(DEBUG && TERSER && {
84
+ composite: false,
85
+ declaration: false,
86
+ declarationMap: false,
87
+ })
88
+ },
89
+ */
90
+ /*
91
+ compilerOptions: {
92
+ declaration: true,
93
+ declarationDir: './types',
94
+ },
95
+ */
96
+ exclude: [
97
+ 'node_modules',
98
+ 'dist',
99
+ 'types',
100
+ '**/*.test.ts',
101
+ '**/*.test.tsx',
102
+ ],
103
+ /*
104
+ clean: true,
105
+ useTsconfigDeclarationDir: true,
106
+ tsconfigOverride: {
107
+ declaration: false,
108
+ exclude: [
109
+ '***.test.ts',
110
+ '***.test.tsx',
111
+ ],
112
+ },
113
+ */
114
+ }),
115
+ babel({
116
+ configFile: getBabelConfigFile(),
117
+ extensions,
118
+ babelHelpers: 'bundled',
119
+ exclude: [
120
+ 'node_modules',
121
+ ],
122
+ }),
123
+ !DEBUG && terser({
124
+ compress: false,
125
+ mangle: false,
126
+ }),
127
+ ].filter(Boolean),
128
+ };
129
+
130
+ export default rollupConfig;