@jterrazz/typescript 4.0.2 → 4.2.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 CHANGED
@@ -24,8 +24,9 @@ npm install @jterrazz/typescript
24
24
  ### 2. Use the build commands
25
25
 
26
26
  ```bash
27
- npx ts-dev # Development with watch mode
28
- npx ts-build # Production build
27
+ npx ts-dev # Development with watch mode
28
+ npx ts-build --app # Production build (ESM + types)
29
+ npx ts-build --lib # Library build (ESM + CJS + types)
29
30
  ```
30
31
 
31
32
  ## What you get
@@ -40,18 +41,23 @@ npx ts-build # Production build
40
41
  | Mode | Output | Description |
41
42
  |------|--------|-------------|
42
43
  | `ts-dev` | `dist/index.js` | ESM only, fast rebuilds (~20ms) |
43
- | `ts-build` | `dist/index.js` | ESM bundle |
44
+ | `ts-build --app` | `dist/index.js` | ESM bundle |
45
+ | | `dist/index.d.ts` | TypeScript declarations |
46
+ | `ts-build --lib` | `dist/index.js` | ESM bundle |
44
47
  | | `dist/index.cjs` | CommonJS bundle |
45
48
  | | `dist/index.d.ts` | TypeScript declarations |
46
49
 
50
+ If `src/instrumentation.ts` exists, it will also generate corresponding `instrumentation.*` files.
51
+
47
52
  ## Project structure
48
53
 
49
54
  ```
50
55
  your-project/
51
56
  ├── src/
52
- └── index.ts # Your TypeScript code
53
- ├── dist/ # Generated files
54
- └── tsconfig.json # Extends this package
57
+ ├── index.ts # Main entry point
58
+ │ └── instrumentation.ts # Optional instrumentation entry point
59
+ ├── dist/ # Generated files
60
+ └── tsconfig.json # Extends this package
55
61
  ```
56
62
 
57
63
  ## How it works
package/bin/ts-build.sh CHANGED
@@ -10,6 +10,26 @@ CYAN_BG='\033[46m'
10
10
  BRIGHT_WHITE='\033[1;30m'
11
11
  NC='\033[0m'
12
12
 
13
+ # Parse arguments (required: --app or --lib)
14
+ BUILD_MODE=""
15
+ for arg in "$@"; do
16
+ case $arg in
17
+ --lib)
18
+ BUILD_MODE="lib"
19
+ ;;
20
+ --app)
21
+ BUILD_MODE="app"
22
+ ;;
23
+ esac
24
+ done
25
+
26
+ if [ -z "$BUILD_MODE" ]; then
27
+ printf "${RED}Error: Build mode required. Use --app or --lib${NC}\n\n"
28
+ printf " --app Build for applications (ESM + types)\n"
29
+ printf " --lib Build for libraries (ESM + CJS + types)\n"
30
+ exit 1
31
+ fi
32
+
13
33
  # Get the directory where the script is being called from (caller's project root)
14
34
  if [ -n "$INIT_CWD" ]; then
15
35
  PROJECT_ROOT="$INIT_CWD"
@@ -27,14 +47,14 @@ done
27
47
  SCRIPT_DIR="$(cd "$(dirname "$SCRIPT_PATH")" && pwd)"
28
48
  CONFIG_PATH="$SCRIPT_DIR/../config/rolldown.build.config.js"
29
49
 
30
- printf "${CYAN_BG}${BRIGHT_WHITE} BUILD ${NC} Building with Rolldown...\n\n"
50
+ printf "${CYAN_BG}${BRIGHT_WHITE} BUILD ${NC} Building with Rolldown (${BUILD_MODE} mode)...\n\n"
31
51
 
32
52
  printf "Project root: %s\n" "$PROJECT_ROOT"
33
53
  printf "Config path: %s\n\n" "$CONFIG_PATH"
34
54
 
35
55
  cd "$PROJECT_ROOT"
36
56
 
37
- if ! npx rolldown --config "$CONFIG_PATH"; then
57
+ if ! BUILD_MODE="$BUILD_MODE" npx rolldown --config "$CONFIG_PATH"; then
38
58
  printf "${RED}✗ Build failed${NC}\n"
39
59
  exit 1
40
60
  fi
@@ -1,12 +1,22 @@
1
+ import { existsSync } from 'node:fs';
1
2
  import { defineConfig } from 'rolldown';
2
3
  import { dts } from 'rolldown-plugin-dts';
3
4
 
5
+ // Build mode: 'lib' = ESM + CJS + types, 'app' = ESM + types only
6
+ const isLibrary = process.env.BUILD_MODE === 'lib';
7
+
4
8
  // Externalize all dependencies (node built-ins + node_modules)
5
9
  const external = [/node_modules/, /^node:/, /^[a-z@]/];
6
10
 
11
+ // Build input with optional instrumentation entry point
12
+ const input = {
13
+ index: 'src/index.ts',
14
+ ...(existsSync('src/instrumentation.ts') && { instrumentation: 'src/instrumentation.ts' }),
15
+ };
16
+
7
17
  // ESM build with .d.ts generation
8
18
  const esmBuild = defineConfig({
9
- input: './src/index.ts',
19
+ input,
10
20
  external,
11
21
  plugins: [
12
22
  dts({
@@ -23,13 +33,14 @@ const esmBuild = defineConfig({
23
33
 
24
34
  // CJS build (no dts - already generated by ESM build)
25
35
  const cjsBuild = defineConfig({
26
- input: './src/index.ts',
36
+ input,
27
37
  external,
28
38
  output: {
29
- file: 'dist/index.cjs',
39
+ dir: 'dist',
40
+ entryFileNames: '[name].cjs',
30
41
  format: 'cjs',
31
42
  sourcemap: true,
32
43
  },
33
44
  });
34
45
 
35
- export default [esmBuild, cjsBuild];
46
+ export default isLibrary ? [esmBuild, cjsBuild] : [esmBuild];
@@ -1,9 +1,16 @@
1
+ import { existsSync } from 'node:fs';
1
2
  import { defineConfig } from 'rolldown';
2
3
 
4
+ // Build input with optional instrumentation entry point
5
+ const input = {
6
+ index: 'src/index.ts',
7
+ ...(existsSync('src/instrumentation.ts') && { instrumentation: 'src/instrumentation.ts' }),
8
+ };
9
+
3
10
  // Dev build - ESM only, no .d.ts (faster rebuilds)
4
11
  // Externalize all dependencies for Node.js apps
5
12
  export default defineConfig({
6
- input: './src/index.ts',
13
+ input,
7
14
  external: [/node_modules/, /^node:/, /^[a-z@]/],
8
15
  output: {
9
16
  dir: 'dist',
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@jterrazz/typescript",
3
3
  "author": "Jean-Baptiste Terrazzoni <contact@jterrazz.com>",
4
- "version": "4.0.2",
4
+ "version": "4.2.0",
5
5
  "files": [
6
6
  "tsconfig",
7
7
  "bin",
@@ -3,8 +3,9 @@
3
3
  "include": ["../../../../src/"],
4
4
 
5
5
  "compilerOptions": {
6
- "moduleResolution": "bundler",
6
+ "moduleResolution": "Bundler",
7
7
  "module": "ESNext",
8
+ "target": "ESNext",
8
9
  "types": ["node"],
9
10
  "strict": true,
10
11
  "experimentalDecorators": true,