@walkeros/config 0.1.0
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/README.md +141 -0
- package/eslint/index.mjs +43 -0
- package/eslint/node.mjs +19 -0
- package/eslint/web.mjs +17 -0
- package/jest/index.mjs +117 -0
- package/jest/node.config.mjs +7 -0
- package/jest/node.setup.ts +13 -0
- package/jest/web.config.mjs +8 -0
- package/jest/web.setup.ts +30 -0
- package/package.json +78 -0
- package/tsconfig/base.json +26 -0
- package/tsconfig/node.json +9 -0
- package/tsconfig/package.json +12 -0
- package/tsconfig/web.json +9 -0
- package/tsup/index.d.ts +16 -0
- package/tsup/index.mjs +83 -0
package/README.md
ADDED
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
# @walkeros/config
|
|
2
|
+
|
|
3
|
+
Unified development configuration package for walkerOS projects. This package provides shared configurations for TypeScript, ESLint, Jest, and tsup build tooling.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install --save-dev @walkeros/config
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Usage
|
|
12
|
+
|
|
13
|
+
### TypeScript Configuration
|
|
14
|
+
|
|
15
|
+
Extend from one of the provided TypeScript configurations in your `tsconfig.json`:
|
|
16
|
+
|
|
17
|
+
```json
|
|
18
|
+
{
|
|
19
|
+
"extends": "@walkeros/config/tsconfig/base.json",
|
|
20
|
+
"compilerOptions": {
|
|
21
|
+
"rootDir": "src"
|
|
22
|
+
},
|
|
23
|
+
"include": ["src/**/*"]
|
|
24
|
+
}
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
**Available configs:**
|
|
28
|
+
- `@walkeros/config/tsconfig/base.json` - Base configuration for all projects
|
|
29
|
+
- `@walkeros/config/tsconfig/web.json` - Browser/web projects (extends base)
|
|
30
|
+
- `@walkeros/config/tsconfig/node.json` - Node.js projects (extends base)
|
|
31
|
+
|
|
32
|
+
### ESLint Configuration
|
|
33
|
+
|
|
34
|
+
Import the configuration in your `eslint.config.mjs`:
|
|
35
|
+
|
|
36
|
+
```javascript
|
|
37
|
+
import baseConfig from '@walkeros/config/eslint';
|
|
38
|
+
|
|
39
|
+
export default [
|
|
40
|
+
...baseConfig,
|
|
41
|
+
{
|
|
42
|
+
// Your custom rules
|
|
43
|
+
},
|
|
44
|
+
];
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
**Available configs:**
|
|
48
|
+
- `@walkeros/config/eslint` - Base configuration with TypeScript and Jest support
|
|
49
|
+
- `@walkeros/config/eslint/web` - Web projects with browser globals
|
|
50
|
+
- `@walkeros/config/eslint/node` - Node.js projects with Node.js rules
|
|
51
|
+
|
|
52
|
+
### Jest Configuration
|
|
53
|
+
|
|
54
|
+
Use the shared Jest configuration in your `jest.config.mjs`:
|
|
55
|
+
|
|
56
|
+
```javascript
|
|
57
|
+
import baseConfig from '@walkeros/config/jest/web.config';
|
|
58
|
+
|
|
59
|
+
export default {
|
|
60
|
+
...baseConfig,
|
|
61
|
+
// Your custom configuration
|
|
62
|
+
};
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
**Available configs:**
|
|
66
|
+
- `@walkeros/config/jest` - Base Jest configuration with SWC transform
|
|
67
|
+
- `@walkeros/config/jest/web.config` - Web projects with jsdom environment
|
|
68
|
+
- `@walkeros/config/jest/node.config` - Node.js projects
|
|
69
|
+
- `@walkeros/config/jest/web.setup` - Web test setup file
|
|
70
|
+
- `@walkeros/config/jest/node.setup` - Node.js test setup file
|
|
71
|
+
|
|
72
|
+
### tsup Configuration
|
|
73
|
+
|
|
74
|
+
Use the shared build helpers in your `tsup.config.ts`:
|
|
75
|
+
|
|
76
|
+
```typescript
|
|
77
|
+
import { defineConfig, buildModules } from '@walkeros/config/tsup';
|
|
78
|
+
|
|
79
|
+
export default defineConfig([buildModules()]);
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
**Available helpers:**
|
|
83
|
+
- `defineConfig` - TypeScript-friendly config wrapper
|
|
84
|
+
- `buildModules()` - Build CJS and ESM modules with type declarations
|
|
85
|
+
- `buildExamples()` - Build example files
|
|
86
|
+
- `buildBrowser()` - Build browser IIFE bundles
|
|
87
|
+
- `buildES5()` - Build ES5-compatible bundles
|
|
88
|
+
|
|
89
|
+
## Features
|
|
90
|
+
|
|
91
|
+
- **TypeScript**: Strict type checking with modern ECMAScript targets
|
|
92
|
+
- **ESLint**: TypeScript, React, and Jest linting with sensible defaults
|
|
93
|
+
- **Jest**: Fast testing with SWC transforms and jsdom support
|
|
94
|
+
- **tsup**: Simple, fast bundling with multiple output formats
|
|
95
|
+
|
|
96
|
+
## Migration from Separate Packages
|
|
97
|
+
|
|
98
|
+
If you were previously using the separate config packages (`@walkeros/tsconfig`, `@walkeros/eslint`, `@walkeros/jest`, `@walkeros/tsup`), update your imports:
|
|
99
|
+
|
|
100
|
+
**Before:**
|
|
101
|
+
```json
|
|
102
|
+
// package.json
|
|
103
|
+
"devDependencies": {
|
|
104
|
+
"@walkeros/eslint": "*",
|
|
105
|
+
"@walkeros/jest": "*",
|
|
106
|
+
"@walkeros/tsconfig": "*",
|
|
107
|
+
"@walkeros/tsup": "*"
|
|
108
|
+
}
|
|
109
|
+
```
|
|
110
|
+
|
|
111
|
+
```typescript
|
|
112
|
+
// Config files
|
|
113
|
+
import from '@walkeros/eslint/index.mjs';
|
|
114
|
+
import from '@walkeros/jest/web.config.mjs';
|
|
115
|
+
import from '@walkeros/tsup';
|
|
116
|
+
{ "extends": "@walkeros/tsconfig/base.json" }
|
|
117
|
+
```
|
|
118
|
+
|
|
119
|
+
**After:**
|
|
120
|
+
```json
|
|
121
|
+
// package.json
|
|
122
|
+
"devDependencies": {
|
|
123
|
+
"@walkeros/config": "^0.1.0"
|
|
124
|
+
}
|
|
125
|
+
```
|
|
126
|
+
|
|
127
|
+
```typescript
|
|
128
|
+
// Config files
|
|
129
|
+
import from '@walkeros/config/eslint';
|
|
130
|
+
import from '@walkeros/config/jest/web.config';
|
|
131
|
+
import from '@walkeros/config/tsup';
|
|
132
|
+
{ "extends": "@walkeros/config/tsconfig/base.json" }
|
|
133
|
+
```
|
|
134
|
+
|
|
135
|
+
## License
|
|
136
|
+
|
|
137
|
+
MIT
|
|
138
|
+
|
|
139
|
+
## Contributing
|
|
140
|
+
|
|
141
|
+
Issues and pull requests are welcome at [github.com/elbwalker/walkerOS](https://github.com/elbwalker/walkerOS).
|
package/eslint/index.mjs
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import typescriptEslint from '@typescript-eslint/eslint-plugin';
|
|
2
|
+
import jest from 'eslint-plugin-jest';
|
|
3
|
+
import globals from 'globals';
|
|
4
|
+
import tsParser from '@typescript-eslint/parser';
|
|
5
|
+
|
|
6
|
+
export default [
|
|
7
|
+
{
|
|
8
|
+
ignores: [
|
|
9
|
+
'**/coverage/**',
|
|
10
|
+
'**/dist/**',
|
|
11
|
+
'**/build/**',
|
|
12
|
+
'**/node_modules/**',
|
|
13
|
+
'**/__mocks__/**',
|
|
14
|
+
],
|
|
15
|
+
},
|
|
16
|
+
{
|
|
17
|
+
files: ['**/*.{js,ts,tsx}'],
|
|
18
|
+
plugins: {
|
|
19
|
+
'@typescript-eslint': typescriptEslint,
|
|
20
|
+
jest,
|
|
21
|
+
},
|
|
22
|
+
languageOptions: {
|
|
23
|
+
parser: tsParser,
|
|
24
|
+
globals: {
|
|
25
|
+
...globals.jest,
|
|
26
|
+
},
|
|
27
|
+
},
|
|
28
|
+
rules: {
|
|
29
|
+
'no-console': 'warn',
|
|
30
|
+
'jest/no-disabled-tests': 'warn',
|
|
31
|
+
'jest/no-focused-tests': 'error',
|
|
32
|
+
'@typescript-eslint/no-explicit-any': 'error',
|
|
33
|
+
},
|
|
34
|
+
},
|
|
35
|
+
{
|
|
36
|
+
// Relaxed rules for test files
|
|
37
|
+
files: ['**/*.test.{js,ts,tsx}', '**/__tests__/**/*.{js,ts,tsx}'],
|
|
38
|
+
rules: {
|
|
39
|
+
'@typescript-eslint/no-explicit-any': 'off',
|
|
40
|
+
'no-console': 'off',
|
|
41
|
+
},
|
|
42
|
+
},
|
|
43
|
+
];
|
package/eslint/node.mjs
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import baseConfig from '@walkeros/config/eslint';
|
|
2
|
+
import globals from 'globals';
|
|
3
|
+
|
|
4
|
+
export default [
|
|
5
|
+
...baseConfig,
|
|
6
|
+
{
|
|
7
|
+
files: ['**/*.{js,ts,tsx}'],
|
|
8
|
+
languageOptions: {
|
|
9
|
+
globals: {
|
|
10
|
+
...globals.node,
|
|
11
|
+
},
|
|
12
|
+
},
|
|
13
|
+
rules: {
|
|
14
|
+
'no-process-exit': 'error',
|
|
15
|
+
'no-path-concat': 'error',
|
|
16
|
+
'no-buffer-constructor': 'error',
|
|
17
|
+
},
|
|
18
|
+
},
|
|
19
|
+
];
|
package/eslint/web.mjs
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import baseConfig from '@walkeros/config/eslint';
|
|
2
|
+
import globals from 'globals';
|
|
3
|
+
|
|
4
|
+
export default [
|
|
5
|
+
...baseConfig,
|
|
6
|
+
{
|
|
7
|
+
files: ['**/*.{js,ts,tsx}'],
|
|
8
|
+
languageOptions: {
|
|
9
|
+
globals: {
|
|
10
|
+
...globals.browser,
|
|
11
|
+
},
|
|
12
|
+
},
|
|
13
|
+
rules: {
|
|
14
|
+
// web-specific rules
|
|
15
|
+
},
|
|
16
|
+
},
|
|
17
|
+
];
|
package/jest/index.mjs
ADDED
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
import path from 'path';
|
|
2
|
+
import { fileURLToPath } from 'url';
|
|
3
|
+
import { readFileSync } from 'fs';
|
|
4
|
+
|
|
5
|
+
const isWatchMode = process.argv.includes('--watchAll');
|
|
6
|
+
const packagesDir = path.join(
|
|
7
|
+
path.dirname(fileURLToPath(import.meta.url)),
|
|
8
|
+
'..',
|
|
9
|
+
'..',
|
|
10
|
+
'..',
|
|
11
|
+
'/',
|
|
12
|
+
);
|
|
13
|
+
|
|
14
|
+
function getDirectory(dir) {
|
|
15
|
+
return path.join(packagesDir, dir);
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
function getModuleMapper() {
|
|
19
|
+
if (!isWatchMode) return {};
|
|
20
|
+
|
|
21
|
+
return {
|
|
22
|
+
'^@walkeros/core$': getDirectory('core/src/'),
|
|
23
|
+
'^@walkeros/collector$': getDirectory('collector/src/'),
|
|
24
|
+
'^@walkeros/web-core$': getDirectory('web/core/src/'),
|
|
25
|
+
'^@walkeros/web-destination-gtag$': getDirectory(
|
|
26
|
+
'web/destinations/gtag/src/',
|
|
27
|
+
),
|
|
28
|
+
'^@walkeros/web-destination-api$': getDirectory(
|
|
29
|
+
'web/destinations/api/src/',
|
|
30
|
+
),
|
|
31
|
+
'^@walkeros/web-destination-meta$': getDirectory(
|
|
32
|
+
'web/destinations/meta/src/',
|
|
33
|
+
),
|
|
34
|
+
'^@walkeros/web-destination-piwikpro$': getDirectory(
|
|
35
|
+
'web/destinations/piwikpro/src/',
|
|
36
|
+
),
|
|
37
|
+
'^@walkeros/web-destination-plausible$': getDirectory(
|
|
38
|
+
'web/destinations/plausible/src/',
|
|
39
|
+
),
|
|
40
|
+
'^@walkeros/web-source-browser$': getDirectory('web/sources/browser/src/'),
|
|
41
|
+
'^@walkeros/web-source-datalayer$': getDirectory(
|
|
42
|
+
'web/sources/dataLayer/src/',
|
|
43
|
+
),
|
|
44
|
+
'^@walkeros/server-core$': getDirectory('server/core/src/'),
|
|
45
|
+
'^@walkeros/server-destination-aws$': getDirectory(
|
|
46
|
+
'server/destinations/aws/src/',
|
|
47
|
+
),
|
|
48
|
+
'^@walkeros/server-destination-gcp$': getDirectory(
|
|
49
|
+
'server/destinations/gcp/src/',
|
|
50
|
+
),
|
|
51
|
+
'^@walkeros/server-destination-meta$': getDirectory(
|
|
52
|
+
'server/destinations/meta/src/',
|
|
53
|
+
),
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
function getGlobals() {
|
|
58
|
+
// Auto-inject package version for tests
|
|
59
|
+
let version = '0.0.0';
|
|
60
|
+
try {
|
|
61
|
+
const packagePath = path.join(process.cwd(), 'package.json');
|
|
62
|
+
const pkg = JSON.parse(readFileSync(packagePath, 'utf8'));
|
|
63
|
+
version = pkg.version || '0.0.0';
|
|
64
|
+
} catch (error) {
|
|
65
|
+
console.warn('Could not read package.json for version injection in tests:', error.message);
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
return {
|
|
69
|
+
__VERSION__: version,
|
|
70
|
+
};
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
const config = {
|
|
74
|
+
transform: {
|
|
75
|
+
'^.+\\.(t|j)sx?$': [
|
|
76
|
+
'@swc/jest',
|
|
77
|
+
{
|
|
78
|
+
jsc: {
|
|
79
|
+
target: 'es2022',
|
|
80
|
+
parser: {
|
|
81
|
+
syntax: 'typescript',
|
|
82
|
+
tsx: true,
|
|
83
|
+
},
|
|
84
|
+
},
|
|
85
|
+
module: {
|
|
86
|
+
type: 'es6',
|
|
87
|
+
},
|
|
88
|
+
},
|
|
89
|
+
],
|
|
90
|
+
},
|
|
91
|
+
transformIgnorePatterns: ['/node_modules/(?!(@walkerOS)/)'],
|
|
92
|
+
testMatch: ['<rootDir>/**/*.test.(ts|tsx|js|jsx)'],
|
|
93
|
+
moduleFileExtensions: ['js', 'ts', 'tsx', 'mjs'],
|
|
94
|
+
rootDir: '.',
|
|
95
|
+
moduleDirectories: ['node_modules', 'src'],
|
|
96
|
+
extensionsToTreatAsEsm: ['.ts', '.tsx'],
|
|
97
|
+
moduleNameMapper: getModuleMapper(),
|
|
98
|
+
globals: getGlobals(),
|
|
99
|
+
|
|
100
|
+
// Performance settings - fixed values for consistent behavior
|
|
101
|
+
maxWorkers: 4,
|
|
102
|
+
testTimeout: 30000,
|
|
103
|
+
forceExit: true,
|
|
104
|
+
clearMocks: true,
|
|
105
|
+
restoreMocks: true,
|
|
106
|
+
detectOpenHandles: true,
|
|
107
|
+
|
|
108
|
+
// Enhanced ignore patterns
|
|
109
|
+
testPathIgnorePatterns: [
|
|
110
|
+
'/node_modules/',
|
|
111
|
+
'/dist/',
|
|
112
|
+
'/build/',
|
|
113
|
+
'/coverage/'
|
|
114
|
+
],
|
|
115
|
+
};
|
|
116
|
+
|
|
117
|
+
export default config;
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import '@testing-library/jest-dom';
|
|
2
|
+
|
|
3
|
+
const mockDataLayer = jest.fn(); //.mockImplementation(console.log);
|
|
4
|
+
|
|
5
|
+
global.beforeEach(() => {
|
|
6
|
+
jest.useFakeTimers();
|
|
7
|
+
|
|
8
|
+
// Mocks
|
|
9
|
+
jest.clearAllMocks();
|
|
10
|
+
jest.resetModules();
|
|
11
|
+
|
|
12
|
+
// reset DOM with event listeners etc.
|
|
13
|
+
document.getElementsByTagName('html')[0].innerHTML = '';
|
|
14
|
+
document.body = document.body.cloneNode() as HTMLElement;
|
|
15
|
+
|
|
16
|
+
// elbLayer and dataLayer
|
|
17
|
+
const w = window as unknown as Record<string, unknown | unknown[]>;
|
|
18
|
+
w.elbLayer = undefined;
|
|
19
|
+
w.dataLayer = [];
|
|
20
|
+
(w.dataLayer as unknown[]).push = mockDataLayer;
|
|
21
|
+
|
|
22
|
+
// Performance
|
|
23
|
+
global.performance.getEntriesByType = jest
|
|
24
|
+
.fn()
|
|
25
|
+
.mockReturnValue([{ type: 'navigate' }]);
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
global.afterEach(() => {});
|
|
29
|
+
|
|
30
|
+
export { mockDataLayer };
|
package/package.json
ADDED
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@walkeros/config",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Shared development configuration for walkerOS packages (TypeScript, ESLint, Jest, tsup)",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"files": [
|
|
7
|
+
"tsconfig/**/*.json",
|
|
8
|
+
"eslint/**/*.mjs",
|
|
9
|
+
"jest/**/*.mjs",
|
|
10
|
+
"jest/**/*.ts",
|
|
11
|
+
"tsup/**/*.mjs",
|
|
12
|
+
"tsup/**/*.d.ts"
|
|
13
|
+
],
|
|
14
|
+
"exports": {
|
|
15
|
+
"./tsconfig/base.json": "./tsconfig/base.json",
|
|
16
|
+
"./tsconfig/web.json": "./tsconfig/web.json",
|
|
17
|
+
"./tsconfig/node.json": "./tsconfig/node.json",
|
|
18
|
+
"./eslint": "./eslint/index.mjs",
|
|
19
|
+
"./eslint/web": "./eslint/web.mjs",
|
|
20
|
+
"./eslint/node": "./eslint/node.mjs",
|
|
21
|
+
"./jest": "./jest/index.mjs",
|
|
22
|
+
"./jest/web.config": "./jest/web.config.mjs",
|
|
23
|
+
"./jest/node.config": "./jest/node.config.mjs",
|
|
24
|
+
"./jest/web.setup": "./jest/web.setup.ts",
|
|
25
|
+
"./jest/node.setup": "./jest/node.setup.ts",
|
|
26
|
+
"./tsup": "./tsup/index.mjs"
|
|
27
|
+
},
|
|
28
|
+
"dependencies": {
|
|
29
|
+
"@swc/core": "^1.11.13",
|
|
30
|
+
"@swc/jest": "^0.2.37",
|
|
31
|
+
"@testing-library/jest-dom": "^6.6.3",
|
|
32
|
+
"@types/jest": "^29.5.14",
|
|
33
|
+
"@eslint/js": "^9.23.0",
|
|
34
|
+
"@typescript-eslint/eslint-plugin": "^8.28.0",
|
|
35
|
+
"@typescript-eslint/parser": "^8.28.0",
|
|
36
|
+
"eslint": "^9.23.0",
|
|
37
|
+
"eslint-config-prettier": "^10.1.1",
|
|
38
|
+
"eslint-plugin-jest": "^28.11.0",
|
|
39
|
+
"eslint-plugin-only-warn": "^1.1.0",
|
|
40
|
+
"eslint-plugin-react": "^7.37.4",
|
|
41
|
+
"eslint-plugin-react-hooks": "^5.2.0",
|
|
42
|
+
"eslint-plugin-turbo": "^2.4.4",
|
|
43
|
+
"globals": "^16.0.0",
|
|
44
|
+
"jest": "^29.7.0",
|
|
45
|
+
"jest-environment-jsdom": "^29.7.0",
|
|
46
|
+
"tsup": "^8.4.0",
|
|
47
|
+
"terser": "^5.39.0",
|
|
48
|
+
"typescript": "^5.8.2"
|
|
49
|
+
},
|
|
50
|
+
"publishConfig": {
|
|
51
|
+
"access": "public"
|
|
52
|
+
},
|
|
53
|
+
"repository": {
|
|
54
|
+
"url": "git+https://github.com/elbwalker/walkerOS.git",
|
|
55
|
+
"directory": "packages/config"
|
|
56
|
+
},
|
|
57
|
+
"author": "elbwalker <hello@elbwalker.com>",
|
|
58
|
+
"homepage": "https://github.com/elbwalker/walkerOS#readme",
|
|
59
|
+
"bugs": {
|
|
60
|
+
"url": "https://github.com/elbwalker/walkerOS/issues"
|
|
61
|
+
},
|
|
62
|
+
"keywords": [
|
|
63
|
+
"walker",
|
|
64
|
+
"walkerOS",
|
|
65
|
+
"config",
|
|
66
|
+
"typescript",
|
|
67
|
+
"eslint",
|
|
68
|
+
"jest",
|
|
69
|
+
"tsup",
|
|
70
|
+
"development"
|
|
71
|
+
],
|
|
72
|
+
"funding": [
|
|
73
|
+
{
|
|
74
|
+
"type": "GitHub Sponsors",
|
|
75
|
+
"url": "https://github.com/sponsors/elbwalker"
|
|
76
|
+
}
|
|
77
|
+
]
|
|
78
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$schema": "https://json.schemastore.org/tsconfig",
|
|
3
|
+
"display": "Base",
|
|
4
|
+
"compilerOptions": {
|
|
5
|
+
"composite": false,
|
|
6
|
+
"declaration": true,
|
|
7
|
+
"declarationMap": true,
|
|
8
|
+
"esModuleInterop": true,
|
|
9
|
+
"forceConsistentCasingInFileNames": true,
|
|
10
|
+
"isolatedModules": true,
|
|
11
|
+
"moduleResolution": "bundler",
|
|
12
|
+
"module": "es2015",
|
|
13
|
+
"noUnusedLocals": false,
|
|
14
|
+
"noUnusedParameters": false,
|
|
15
|
+
"preserveWatchOutput": true,
|
|
16
|
+
"skipLibCheck": true,
|
|
17
|
+
"strict": true,
|
|
18
|
+
"target": "es2022",
|
|
19
|
+
"allowJs": true,
|
|
20
|
+
"resolveJsonModule": true,
|
|
21
|
+
"sourceMap": true,
|
|
22
|
+
"outDir": "dist",
|
|
23
|
+
"baseUrl": "."
|
|
24
|
+
},
|
|
25
|
+
"exclude": ["node_modules", "**/dist", "**/*.d.ts"]
|
|
26
|
+
}
|
package/tsup/index.d.ts
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { Options, defineConfig } from 'tsup';
|
|
2
|
+
|
|
3
|
+
declare const baseConfig: Options;
|
|
4
|
+
declare const buildModules: (customConfig?: Partial<Options>) => Options;
|
|
5
|
+
declare const buildExamples: (customConfig?: Partial<Options>) => Options;
|
|
6
|
+
declare const buildBrowser: (customConfig?: Partial<Options>) => Options;
|
|
7
|
+
declare const buildES5: (customConfig?: Partial<Options>) => Options;
|
|
8
|
+
|
|
9
|
+
export {
|
|
10
|
+
baseConfig,
|
|
11
|
+
defineConfig,
|
|
12
|
+
buildModules,
|
|
13
|
+
buildExamples,
|
|
14
|
+
buildBrowser,
|
|
15
|
+
buildES5,
|
|
16
|
+
};
|
package/tsup/index.mjs
ADDED
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import { defineConfig } from 'tsup';
|
|
2
|
+
import { readFileSync } from 'fs';
|
|
3
|
+
import { resolve } from 'path';
|
|
4
|
+
|
|
5
|
+
const baseConfig = {
|
|
6
|
+
entry: ['src/index.ts'],
|
|
7
|
+
minify: 'terser',
|
|
8
|
+
splitting: false,
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
// Modules
|
|
12
|
+
const buildModules = (customConfig = {}) => {
|
|
13
|
+
// Auto-inject package version
|
|
14
|
+
let version = '0.0.0';
|
|
15
|
+
try {
|
|
16
|
+
const packagePath = resolve(process.cwd(), 'package.json');
|
|
17
|
+
const pkg = JSON.parse(readFileSync(packagePath, 'utf8'));
|
|
18
|
+
version = pkg.version || '0.0.0';
|
|
19
|
+
} catch (error) {
|
|
20
|
+
console.warn('Could not read package.json for version injection:', error.message);
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
return {
|
|
24
|
+
...baseConfig,
|
|
25
|
+
clean: true,
|
|
26
|
+
format: ['cjs', 'esm'],
|
|
27
|
+
outExtension({ format }) {
|
|
28
|
+
return { js: format === 'esm' ? '.mjs' : '.js' };
|
|
29
|
+
},
|
|
30
|
+
dts: true,
|
|
31
|
+
sourcemap: true,
|
|
32
|
+
declaration: true,
|
|
33
|
+
declarationMap: true,
|
|
34
|
+
define: {
|
|
35
|
+
__VERSION__: JSON.stringify(version),
|
|
36
|
+
...customConfig.define,
|
|
37
|
+
},
|
|
38
|
+
...customConfig,
|
|
39
|
+
};
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
// Examples
|
|
43
|
+
const buildExamples = (customConfig = {}) => ({
|
|
44
|
+
...baseConfig,
|
|
45
|
+
entry: { 'examples/index': 'src/examples/index.ts' },
|
|
46
|
+
dts: true,
|
|
47
|
+
minify: false,
|
|
48
|
+
format: ['cjs', 'esm'],
|
|
49
|
+
outExtension({ format }) {
|
|
50
|
+
return { js: format === 'esm' ? '.mjs' : '.js' };
|
|
51
|
+
},
|
|
52
|
+
...customConfig,
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
// Browser
|
|
56
|
+
const buildBrowser = (customConfig = {}) => ({
|
|
57
|
+
...baseConfig,
|
|
58
|
+
format: ['iife'],
|
|
59
|
+
outExtension() {
|
|
60
|
+
return { js: `.browser.js` };
|
|
61
|
+
},
|
|
62
|
+
...customConfig,
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
// ES5
|
|
66
|
+
const buildES5 = (customConfig = {}) => ({
|
|
67
|
+
...baseConfig,
|
|
68
|
+
format: ['iife'],
|
|
69
|
+
target: 'es5',
|
|
70
|
+
outExtension() {
|
|
71
|
+
return { js: `.es5.js` };
|
|
72
|
+
},
|
|
73
|
+
...customConfig,
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
export {
|
|
77
|
+
baseConfig,
|
|
78
|
+
buildModules,
|
|
79
|
+
buildExamples,
|
|
80
|
+
buildBrowser,
|
|
81
|
+
buildES5,
|
|
82
|
+
defineConfig,
|
|
83
|
+
};
|