monocrate 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/LICENSE +21 -0
- package/README.md +194 -0
- package/dist/build-dependency-graph.d.ts +8 -0
- package/dist/build-dependency-graph.d.ts.map +1 -0
- package/dist/build-dependency-graph.js +39 -0
- package/dist/build-dependency-graph.js.map +1 -0
- package/dist/build-package-map.d.ts +4 -0
- package/dist/build-package-map.d.ts.map +1 -0
- package/dist/build-package-map.js +43 -0
- package/dist/build-package-map.js.map +1 -0
- package/dist/bundle.d.ts +3 -0
- package/dist/bundle.d.ts.map +1 -0
- package/dist/bundle.js +11 -0
- package/dist/bundle.js.map +1 -0
- package/dist/bundler.d.ts +3 -0
- package/dist/bundler.d.ts.map +1 -0
- package/dist/bundler.js +62 -0
- package/dist/bundler.js.map +1 -0
- package/dist/copy-bundler.d.ts +3 -0
- package/dist/copy-bundler.d.ts.map +1 -0
- package/dist/copy-bundler.js +11 -0
- package/dist/copy-bundler.js.map +1 -0
- package/dist/dependency-graph.d.ts +3 -0
- package/dist/dependency-graph.d.ts.map +1 -0
- package/dist/dependency-graph.js +44 -0
- package/dist/dependency-graph.js.map +1 -0
- package/dist/dist-copier.d.ts +10 -0
- package/dist/dist-copier.d.ts.map +1 -0
- package/dist/dist-copier.js +44 -0
- package/dist/dist-copier.js.map +1 -0
- package/dist/import-rewriter.d.ts +12 -0
- package/dist/import-rewriter.d.ts.map +1 -0
- package/dist/import-rewriter.js +88 -0
- package/dist/import-rewriter.js.map +1 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +2 -0
- package/dist/index.js.map +1 -0
- package/dist/index.test.d.ts +2 -0
- package/dist/index.test.d.ts.map +1 -0
- package/dist/index.test.js +110 -0
- package/dist/index.test.js.map +1 -0
- package/dist/main.d.ts +3 -0
- package/dist/main.d.ts.map +1 -0
- package/dist/main.js +4 -0
- package/dist/main.js.map +1 -0
- package/dist/monocrate-cli.d.ts +2 -0
- package/dist/monocrate-cli.d.ts.map +1 -0
- package/dist/monocrate-cli.js +46 -0
- package/dist/monocrate-cli.js.map +1 -0
- package/dist/monocrate.d.ts +14 -0
- package/dist/monocrate.d.ts.map +1 -0
- package/dist/monocrate.js +27 -0
- package/dist/monocrate.js.map +1 -0
- package/dist/monocrate.test.d.ts +2 -0
- package/dist/monocrate.test.d.ts.map +1 -0
- package/dist/monocrate.test.js +998 -0
- package/dist/monocrate.test.js.map +1 -0
- package/dist/monorepo.d.ts +9 -0
- package/dist/monorepo.d.ts.map +1 -0
- package/dist/monorepo.js +82 -0
- package/dist/monorepo.js.map +1 -0
- package/dist/package-json.d.ts +38 -0
- package/dist/package-json.d.ts.map +1 -0
- package/dist/package-json.js +25 -0
- package/dist/package-json.js.map +1 -0
- package/dist/package-map.d.ts +8 -0
- package/dist/package-map.d.ts.map +1 -0
- package/dist/package-map.js +2 -0
- package/dist/package-map.js.map +1 -0
- package/dist/package-transformer.d.ts +5 -0
- package/dist/package-transformer.d.ts.map +1 -0
- package/dist/package-transformer.js +20 -0
- package/dist/package-transformer.js.map +1 -0
- package/dist/transform-package-json.d.ts +5 -0
- package/dist/transform-package-json.d.ts.map +1 -0
- package/dist/transform-package-json.js +19 -0
- package/dist/transform-package-json.js.map +1 -0
- package/dist/types.d.ts +2 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +2 -0
- package/dist/types.js.map +1 -0
- package/package.json +69 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2024 Monocrate Contributors
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,194 @@
|
|
|
1
|
+
# Monocrate
|
|
2
|
+
|
|
3
|
+
> From monorepo to npm in one command
|
|
4
|
+
|
|
5
|
+
Monocrate bundles monorepo packages for npm publishing by automatically resolving in-repo dependencies, copying compiled code, and generating a unified package.json with all third-party dependencies merged.
|
|
6
|
+
|
|
7
|
+
## The Problem
|
|
8
|
+
|
|
9
|
+
Publishing a package from a monorepo to npm is surprisingly painful. Your package might depend on other internal packages (like `@myorg/utils` or `@myorg/core`), but npm doesn't understand workspace dependencies. You end up with one of these bad options:
|
|
10
|
+
|
|
11
|
+
1. **Publish everything** - Every internal dependency must be published separately, even if they're implementation details
|
|
12
|
+
2. **Manual bundling** - Copy files, manually merge package.json dependencies, hope you didn't miss anything
|
|
13
|
+
3. **Complex build pipelines** - Esbuild/Rollup/Webpack configurations that bundle everything into a single file, losing the module structure
|
|
14
|
+
|
|
15
|
+
## The Solution
|
|
16
|
+
|
|
17
|
+
Monocrate takes a different approach: it bundles your package and all its in-repo dependencies into a single publishable directory, preserving the original module structure. Third-party dependencies are collected from all packages and merged into a single package.json.
|
|
18
|
+
|
|
19
|
+
```
|
|
20
|
+
monorepo/
|
|
21
|
+
packages/
|
|
22
|
+
app/ <-- You want to publish this
|
|
23
|
+
utils/ <-- app depends on this
|
|
24
|
+
core/ <-- utils depends on this
|
|
25
|
+
|
|
26
|
+
$ monocrate bundle @myorg/app --output ./publish
|
|
27
|
+
|
|
28
|
+
publish/
|
|
29
|
+
index.js <-- app's compiled code
|
|
30
|
+
_deps/
|
|
31
|
+
_myorg_utils/ <-- utils' compiled code
|
|
32
|
+
_myorg_core/ <-- core's compiled code
|
|
33
|
+
package.json <-- Merged dependencies from all packages
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
## Installation
|
|
37
|
+
|
|
38
|
+
```bash
|
|
39
|
+
npm install -g monocrate
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
Or use without installing:
|
|
43
|
+
|
|
44
|
+
```bash
|
|
45
|
+
npx monocrate bundle my-package --output ./publish
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
## Quick Start
|
|
49
|
+
|
|
50
|
+
**1. Build your packages**
|
|
51
|
+
|
|
52
|
+
```bash
|
|
53
|
+
# Ensure all packages have been compiled to their dist/ directories
|
|
54
|
+
npm run build --workspaces
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
**2. Bundle for publishing**
|
|
58
|
+
|
|
59
|
+
```bash
|
|
60
|
+
monocrate bundle @myorg/app --output ./publish
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
**3. Publish to npm**
|
|
64
|
+
|
|
65
|
+
```bash
|
|
66
|
+
cd publish && npm publish
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
## Programmatic API
|
|
70
|
+
|
|
71
|
+
Monocrate can be used as a library in your build scripts:
|
|
72
|
+
|
|
73
|
+
```typescript
|
|
74
|
+
import { bundle } from 'monocrate';
|
|
75
|
+
|
|
76
|
+
const result = await bundle({
|
|
77
|
+
packagePath: '/path/to/monorepo/packages/my-app',
|
|
78
|
+
monorepoRoot: '/path/to/monorepo',
|
|
79
|
+
outputDir: '/tmp/my-app-bundle',
|
|
80
|
+
});
|
|
81
|
+
|
|
82
|
+
if (result.success) {
|
|
83
|
+
console.log('Bundle created at:', result.outputPath);
|
|
84
|
+
console.log('Included packages:', result.includedPackages);
|
|
85
|
+
console.log('Dependencies:', result.mergedDependencies);
|
|
86
|
+
} else {
|
|
87
|
+
console.error('Bundle failed:', result.error);
|
|
88
|
+
console.error('Details:', result.details);
|
|
89
|
+
}
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
### Convenience Function
|
|
93
|
+
|
|
94
|
+
For simpler use cases when running from the monorepo root:
|
|
95
|
+
|
|
96
|
+
```typescript
|
|
97
|
+
import { bundlePackage } from 'monocrate';
|
|
98
|
+
|
|
99
|
+
// Automatically discovers packages from workspace configuration
|
|
100
|
+
const result = await bundlePackage('@myorg/app', '/tmp/bundle');
|
|
101
|
+
```
|
|
102
|
+
|
|
103
|
+
## Configuration Options
|
|
104
|
+
|
|
105
|
+
| Option | Type | Default | Description |
|
|
106
|
+
|--------|------|---------|-------------|
|
|
107
|
+
| `packagePath` | `string` | required | Absolute path to the package to bundle |
|
|
108
|
+
| `monorepoRoot` | `string` | required | Absolute path to the monorepo root |
|
|
109
|
+
| `outputDir` | `string` | required | Absolute path to the output directory |
|
|
110
|
+
| `includeSourceMaps` | `boolean` | `true` | Include `.map` files in the bundle |
|
|
111
|
+
| `includeDeclarations` | `boolean` | `true` | Include `.d.ts` files in the bundle |
|
|
112
|
+
| `versionConflictStrategy` | `'highest' \| 'error' \| 'warn'` | `'warn'` | How to handle version conflicts |
|
|
113
|
+
| `cleanOutputDir` | `boolean` | `true` | Remove existing output directory before bundling |
|
|
114
|
+
| `distDirName` | `string` | `'dist'` | Name of the compiled output directory |
|
|
115
|
+
|
|
116
|
+
### Version Conflict Strategies
|
|
117
|
+
|
|
118
|
+
When multiple packages depend on the same third-party package with different versions:
|
|
119
|
+
|
|
120
|
+
- **`'highest'`** - Silently use the highest semver-compatible version
|
|
121
|
+
- **`'warn'`** - Use highest version, but log a warning
|
|
122
|
+
- **`'error'`** - Fail the bundle operation
|
|
123
|
+
|
|
124
|
+
```typescript
|
|
125
|
+
const result = await bundle({
|
|
126
|
+
// ...
|
|
127
|
+
versionConflictStrategy: 'error', // Strict mode
|
|
128
|
+
});
|
|
129
|
+
```
|
|
130
|
+
|
|
131
|
+
## How It Works
|
|
132
|
+
|
|
133
|
+
1. **Discover packages** - Reads workspace configuration (npm, yarn, or pnpm) to find all packages in the monorepo
|
|
134
|
+
|
|
135
|
+
2. **Build dependency graph** - Starting from your target package, recursively finds all in-repo dependencies and builds a topologically-sorted graph
|
|
136
|
+
|
|
137
|
+
3. **Validate builds** - Ensures all packages have been compiled (have a `dist/` directory)
|
|
138
|
+
|
|
139
|
+
4. **Assemble bundle** - Copies compiled code:
|
|
140
|
+
- Root package's `dist/` goes to output root
|
|
141
|
+
- Dependencies' `dist/` go to `_deps/<package-name>/`
|
|
142
|
+
|
|
143
|
+
5. **Transform package.json** - Generates a publish-ready package.json:
|
|
144
|
+
- Removes workspace-specific fields (`workspaces`, `private`, `devDependencies`)
|
|
145
|
+
- Removes in-repo dependencies
|
|
146
|
+
- Merges third-party dependencies from all included packages
|
|
147
|
+
|
|
148
|
+
## Bundle Result
|
|
149
|
+
|
|
150
|
+
The `bundle()` function returns a discriminated union:
|
|
151
|
+
|
|
152
|
+
```typescript
|
|
153
|
+
// Success
|
|
154
|
+
{
|
|
155
|
+
success: true,
|
|
156
|
+
outputPath: string, // Path to the bundle
|
|
157
|
+
packageJson: PackageJson, // Generated package.json
|
|
158
|
+
mergedDependencies: object, // All third-party deps
|
|
159
|
+
includedPackages: string[], // List of bundled packages
|
|
160
|
+
versionConflicts: VersionConflict[], // Any conflicts found
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
// Failure
|
|
164
|
+
{
|
|
165
|
+
success: false,
|
|
166
|
+
error: string, // Error message
|
|
167
|
+
details?: string, // Additional context
|
|
168
|
+
cause?: Error, // Underlying error
|
|
169
|
+
}
|
|
170
|
+
```
|
|
171
|
+
|
|
172
|
+
## Requirements
|
|
173
|
+
|
|
174
|
+
- **Node.js 20+**
|
|
175
|
+
- **Built packages** - All packages must have a `dist/` directory with compiled code
|
|
176
|
+
- **Workspace configuration** - npm workspaces, yarn workspaces, or pnpm-workspace.yaml
|
|
177
|
+
|
|
178
|
+
## Supported Package Managers
|
|
179
|
+
|
|
180
|
+
Monocrate automatically detects your package manager from:
|
|
181
|
+
|
|
182
|
+
- `pnpm-workspace.yaml`
|
|
183
|
+
- `workspaces` field in root `package.json`
|
|
184
|
+
- Lock files (`pnpm-lock.yaml`, `yarn.lock`, `package-lock.json`)
|
|
185
|
+
|
|
186
|
+
## Documentation
|
|
187
|
+
|
|
188
|
+
- [API Reference](./docs/api.md) - Complete programmatic API documentation
|
|
189
|
+
- [How It Works](./docs/how-it-works.md) - Deep dive into the bundling process
|
|
190
|
+
- [Troubleshooting](./docs/troubleshooting.md) - Common errors and solutions
|
|
191
|
+
|
|
192
|
+
## License
|
|
193
|
+
|
|
194
|
+
MIT
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { MonorepoPackage } from './monorepo.js';
|
|
2
|
+
export interface DependencyGraph {
|
|
3
|
+
packageToBundle: MonorepoPackage;
|
|
4
|
+
inRepoDeps: MonorepoPackage[];
|
|
5
|
+
allThirdPartyDeps: Partial<Record<string, string>>;
|
|
6
|
+
}
|
|
7
|
+
export declare function buildDependencyGraph(sourceDir: string, monorepoRoot: string): Promise<DependencyGraph>;
|
|
8
|
+
//# sourceMappingURL=build-dependency-graph.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"build-dependency-graph.d.ts","sourceRoot":"","sources":["../src/build-dependency-graph.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,eAAe,CAAA;AAGpD,MAAM,WAAW,eAAe;IAC9B,eAAe,EAAE,eAAe,CAAA;IAChC,UAAU,EAAE,eAAe,EAAE,CAAA;IAC7B,iBAAiB,EAAE,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAAA;CACnD;AAED,wBAAsB,oBAAoB,CAAC,SAAS,EAAE,MAAM,EAAE,YAAY,EAAE,MAAM,GAAG,OAAO,CAAC,eAAe,CAAC,CAyC5G"}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { discoverMonorepoPackages } from './monorepo.js';
|
|
2
|
+
export async function buildDependencyGraph(sourceDir, monorepoRoot) {
|
|
3
|
+
const allRepoPackages = await discoverMonorepoPackages(monorepoRoot);
|
|
4
|
+
const packageToBundle = [...allRepoPackages.values()].find((at) => at.path === sourceDir);
|
|
5
|
+
if (!packageToBundle) {
|
|
6
|
+
throw new Error(`Could not find a monorepo package at ${sourceDir}`);
|
|
7
|
+
}
|
|
8
|
+
const allThirdPartyDeps = {};
|
|
9
|
+
const visited = new Map();
|
|
10
|
+
function collectDeps(pkg) {
|
|
11
|
+
if (visited.has(pkg.name)) {
|
|
12
|
+
return;
|
|
13
|
+
}
|
|
14
|
+
visited.set(pkg.name, pkg);
|
|
15
|
+
const deps = pkg.packageJson.dependencies ?? {};
|
|
16
|
+
for (const [depName, depVersion] of Object.entries(deps)) {
|
|
17
|
+
if (!depVersion) {
|
|
18
|
+
throw new Error(`no version for dep ${depName} in ${pkg.name}`);
|
|
19
|
+
}
|
|
20
|
+
const depPackage = allRepoPackages.get(depName);
|
|
21
|
+
if (depPackage) {
|
|
22
|
+
// Is an in-repo dep
|
|
23
|
+
collectDeps(depPackage);
|
|
24
|
+
}
|
|
25
|
+
else {
|
|
26
|
+
if (!(depName in allThirdPartyDeps)) {
|
|
27
|
+
allThirdPartyDeps[depName] = depVersion;
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
collectDeps(packageToBundle);
|
|
33
|
+
return {
|
|
34
|
+
packageToBundle,
|
|
35
|
+
inRepoDeps: [...visited.values()].filter((at) => at !== packageToBundle),
|
|
36
|
+
allThirdPartyDeps,
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
//# sourceMappingURL=build-dependency-graph.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"build-dependency-graph.js","sourceRoot":"","sources":["../src/build-dependency-graph.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,wBAAwB,EAAE,MAAM,eAAe,CAAA;AAQxD,MAAM,CAAC,KAAK,UAAU,oBAAoB,CAAC,SAAiB,EAAE,YAAoB;IAChF,MAAM,eAAe,GAAG,MAAM,wBAAwB,CAAC,YAAY,CAAC,CAAA;IACpE,MAAM,eAAe,GAAG,CAAC,GAAG,eAAe,CAAC,MAAM,EAAE,CAAC,CAAC,IAAI,CAAC,CAAC,EAAE,EAAE,EAAE,CAAC,EAAE,CAAC,IAAI,KAAK,SAAS,CAAC,CAAA;IACzF,IAAI,CAAC,eAAe,EAAE,CAAC;QACrB,MAAM,IAAI,KAAK,CAAC,wCAAwC,SAAS,EAAE,CAAC,CAAA;IACtE,CAAC;IAED,MAAM,iBAAiB,GAAoC,EAAE,CAAA;IAC7D,MAAM,OAAO,GAAG,IAAI,GAAG,EAA2B,CAAA;IAElD,SAAS,WAAW,CAAC,GAAoB;QACvC,IAAI,OAAO,CAAC,GAAG,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE,CAAC;YAC1B,OAAM;QACR,CAAC;QACD,OAAO,CAAC,GAAG,CAAC,GAAG,CAAC,IAAI,EAAE,GAAG,CAAC,CAAA;QAE1B,MAAM,IAAI,GAAG,GAAG,CAAC,WAAW,CAAC,YAAY,IAAI,EAAE,CAAA;QAE/C,KAAK,MAAM,CAAC,OAAO,EAAE,UAAU,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,IAAI,CAAC,EAAE,CAAC;YACzD,IAAI,CAAC,UAAU,EAAE,CAAC;gBAChB,MAAM,IAAI,KAAK,CAAC,sBAAsB,OAAO,OAAO,GAAG,CAAC,IAAI,EAAE,CAAC,CAAA;YACjE,CAAC;YACD,MAAM,UAAU,GAAG,eAAe,CAAC,GAAG,CAAC,OAAO,CAAC,CAAA;YAC/C,IAAI,UAAU,EAAE,CAAC;gBACf,oBAAoB;gBACpB,WAAW,CAAC,UAAU,CAAC,CAAA;YACzB,CAAC;iBAAM,CAAC;gBACN,IAAI,CAAC,CAAC,OAAO,IAAI,iBAAiB,CAAC,EAAE,CAAC;oBACpC,iBAAiB,CAAC,OAAO,CAAC,GAAG,UAAU,CAAA;gBACzC,CAAC;YACH,CAAC;QACH,CAAC;IACH,CAAC;IAED,WAAW,CAAC,eAAe,CAAC,CAAA;IAE5B,OAAO;QACL,eAAe;QACf,UAAU,EAAE,CAAC,GAAG,OAAO,CAAC,MAAM,EAAE,CAAC,CAAC,MAAM,CAAC,CAAC,EAAE,EAAE,EAAE,CAAC,EAAE,KAAK,eAAe,CAAC;QACxE,iBAAiB;KAClB,CAAA;AACH,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"build-package-map.d.ts","sourceRoot":"","sources":["../src/build-package-map.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAA;AAClD,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,6BAA6B,CAAA;AA2ClE,wBAAgB,eAAe,CAAC,KAAK,EAAE,eAAe,EAAE,YAAY,EAAE,MAAM,GAAG,UAAU,CAUxF"}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import * as fs from 'node:fs';
|
|
2
|
+
import * as path from 'node:path';
|
|
3
|
+
const DEFAULT_DIST_DIR = 'dist';
|
|
4
|
+
const DEFAULT_ENTRY_POINT = 'dist/index.js';
|
|
5
|
+
function resolveDistDir(main) {
|
|
6
|
+
if (main === undefined) {
|
|
7
|
+
return DEFAULT_DIST_DIR;
|
|
8
|
+
}
|
|
9
|
+
const dir = path.dirname(main);
|
|
10
|
+
return dir === '' || dir === '.' ? DEFAULT_DIST_DIR : dir;
|
|
11
|
+
}
|
|
12
|
+
function resolveEntryPoint(main) {
|
|
13
|
+
return main ?? DEFAULT_ENTRY_POINT;
|
|
14
|
+
}
|
|
15
|
+
function registerPackageLocation(packageMap, pkg, outputPrefix) {
|
|
16
|
+
const distDir = resolveDistDir(pkg.packageJson.main);
|
|
17
|
+
const sourceDistDir = path.resolve(pkg.path, distDir);
|
|
18
|
+
if (!fs.existsSync(sourceDistDir)) {
|
|
19
|
+
throw new Error(`dist directory not found at ${sourceDistDir}. Did you run the build for ${pkg.name}?`);
|
|
20
|
+
}
|
|
21
|
+
const outputDistDir = path.join(outputPrefix, distDir);
|
|
22
|
+
packageMap.set(pkg.name, {
|
|
23
|
+
name: pkg.name,
|
|
24
|
+
sourceDistDir,
|
|
25
|
+
outputDistDir,
|
|
26
|
+
outputEntryPoint: path.join(outputPrefix, resolveEntryPoint(pkg.packageJson.main)),
|
|
27
|
+
resolveSubpath(subpath) {
|
|
28
|
+
return path.join(outputDistDir, subpath);
|
|
29
|
+
},
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
function computeDepOutputPrefix(dep, monorepoRoot) {
|
|
33
|
+
return path.join('deps', path.relative(monorepoRoot, dep.path));
|
|
34
|
+
}
|
|
35
|
+
export function buildPackageMap(graph, monorepoRoot) {
|
|
36
|
+
const packageMap = new Map();
|
|
37
|
+
registerPackageLocation(packageMap, graph.packageToBundle, '');
|
|
38
|
+
for (const dep of graph.inRepoDeps) {
|
|
39
|
+
registerPackageLocation(packageMap, dep, computeDepOutputPrefix(dep, monorepoRoot));
|
|
40
|
+
}
|
|
41
|
+
return packageMap;
|
|
42
|
+
}
|
|
43
|
+
//# sourceMappingURL=build-package-map.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"build-package-map.js","sourceRoot":"","sources":["../src/build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AAG,CAAC,WAAW,CAAC,IAAI,CAAC,CAAC;QAClF,cAAc,CAAC,OAAe;YAC5B,OAAO,IAAI,CAAC,IAAI,CAAC,aAAa,EAAE,OAAO,CAAC,CAAA;QAC1C,CAAC;KACF,CAAC,CAAA;AACJ,CAAC;AAED,SAAS,sBAAsB,CAAC,GAAoB,EAAE,YAAoB;IACxE,OAAO,IAAI,CAAC,IAAI,CAAC,MAAM,EAAE,IAAI,CAAC,QAAQ,CAAC,YAAY,EAAE,GAAG,CAAC,IAAI,CAAC,CAAC,CAAA;AACjE,CAAC;AAED,MAAM,UAAU,eAAe,CAAC,KAAsB,EAAE,YAAoB;IAC1E,MAAM,UAAU,GAAe,IAAI,GAAG,EAAE,CAAA;IAExC,uBAAuB,CAAC,UAAU,EAAE,KAAK,CAAC,eAAe,EAAE,EAAE,CAAC,CAAA;IAE9D,KAAK,MAAM,GAAG,IAAI,KAAK,CAAC,UAAU,EAAE,CAAC;QACnC,uBAAuB,CAAC,UAAU,EAAE,GAAG,EAAE,sBAAsB,CAAC,GAAG,EAAE,YAAY,CAAC,CAAC,CAAA;IACrF,CAAC;IAED,OAAO,UAAU,CAAA;AACnB,CAAC"}
|
package/dist/bundle.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"bundle.d.ts","sourceRoot":"","sources":["../src/bundle.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,6BAA6B,CAAA;AAElE,wBAAsB,MAAM,CAAC,KAAK,EAAE,eAAe,EAAE,YAAY,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAO3G"}
|
package/dist/bundle.js
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import * as fsPromises from 'node:fs/promises';
|
|
2
|
+
import { buildPackageMap } from './build-package-map.js';
|
|
3
|
+
import { DistCopier } from './dist-copier.js';
|
|
4
|
+
import { ImportRewriter } from './import-rewriter.js';
|
|
5
|
+
export async function bundle(graph, monorepoRoot, outputDir) {
|
|
6
|
+
const packageMap = buildPackageMap(graph, monorepoRoot);
|
|
7
|
+
await fsPromises.mkdir(outputDir, { recursive: true });
|
|
8
|
+
const copiedFiles = await new DistCopier(packageMap, outputDir).copy();
|
|
9
|
+
await new ImportRewriter(packageMap, outputDir).rewriteAll(copiedFiles);
|
|
10
|
+
}
|
|
11
|
+
//# sourceMappingURL=bundle.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"bundle.js","sourceRoot":"","sources":["../src/bundle.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,UAAU,MAAM,kBAAkB,CAAA;AAC9C,OAAO,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAA;AACxD,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAA;AAC7C,OAAO,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAA;AAGrD,MAAM,CAAC,KAAK,UAAU,MAAM,CAAC,KAAsB,EAAE,YAAoB,EAAE,SAAiB;IAC1F,MAAM,UAAU,GAAG,eAAe,CAAC,KAAK,EAAE,YAAY,CAAC,CAAA;IAEvD,MAAM,UAAU,CAAC,KAAK,CAAC,SAAS,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,CAAA;IAEtD,MAAM,WAAW,GAAG,MAAM,IAAI,UAAU,CAAC,UAAU,EAAE,SAAS,CAAC,CAAC,IAAI,EAAE,CAAA;IACtE,MAAM,IAAI,cAAc,CAAC,UAAU,EAAE,SAAS,CAAC,CAAC,UAAU,CAAC,WAAW,CAAC,CAAA;AACzE,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"bundler.d.ts","sourceRoot":"","sources":["../src/bundler.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,eAAe,EAAmB,MAAM,YAAY,CAAA;AA8ClE,wBAAsB,MAAM,CAAC,KAAK,EAAE,eAAe,EAAE,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAmBrF"}
|
package/dist/bundler.js
ADDED
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import * as fs from 'node:fs/promises';
|
|
2
|
+
import * as fsSync from 'node:fs';
|
|
3
|
+
import module from 'node:module';
|
|
4
|
+
import * as path from 'node:path';
|
|
5
|
+
import * as esbuild from 'esbuild';
|
|
6
|
+
import { getExternalDependencies } from './dependency-graph.js';
|
|
7
|
+
const NODE_BUILTIN_MODULES = module.builtinModules.flatMap((m) => [m, `node:${m}`]);
|
|
8
|
+
function findEntryPoint(packageDir, packageJson) {
|
|
9
|
+
const possibleEntries = [
|
|
10
|
+
packageJson.source,
|
|
11
|
+
packageJson.main,
|
|
12
|
+
'src/index.ts',
|
|
13
|
+
'src/index.js',
|
|
14
|
+
'index.ts',
|
|
15
|
+
'index.js',
|
|
16
|
+
].filter((e) => typeof e === 'string');
|
|
17
|
+
for (const entry of possibleEntries) {
|
|
18
|
+
const fullPath = path.resolve(packageDir, entry);
|
|
19
|
+
if (fsSync.existsSync(fullPath)) {
|
|
20
|
+
return fullPath;
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
throw new Error(`Could not find entry point in ${packageDir}`);
|
|
24
|
+
}
|
|
25
|
+
function createInRepoResolverPlugin(inRepoDeps) {
|
|
26
|
+
const packageMap = new Map();
|
|
27
|
+
for (const dep of inRepoDeps) {
|
|
28
|
+
const entryPoint = findEntryPoint(dep.path, dep.packageJson);
|
|
29
|
+
packageMap.set(dep.name, entryPoint);
|
|
30
|
+
}
|
|
31
|
+
return {
|
|
32
|
+
name: 'in-repo-resolver',
|
|
33
|
+
setup(build) {
|
|
34
|
+
build.onResolve({ filter: /.*/ }, (args) => {
|
|
35
|
+
const resolved = packageMap.get(args.path);
|
|
36
|
+
if (resolved) {
|
|
37
|
+
return { path: resolved };
|
|
38
|
+
}
|
|
39
|
+
return null;
|
|
40
|
+
});
|
|
41
|
+
},
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
export async function bundle(graph, outputDir) {
|
|
45
|
+
const entryPoint = findEntryPoint(graph.root.path, graph.root.packageJson);
|
|
46
|
+
const externalDeps = getExternalDependencies(graph);
|
|
47
|
+
const resolverPlugin = createInRepoResolverPlugin(graph.inRepoDeps);
|
|
48
|
+
await fs.mkdir(outputDir, { recursive: true });
|
|
49
|
+
await esbuild.build({
|
|
50
|
+
entryPoints: [entryPoint],
|
|
51
|
+
bundle: true,
|
|
52
|
+
platform: 'node',
|
|
53
|
+
target: 'node20',
|
|
54
|
+
format: 'esm',
|
|
55
|
+
outfile: path.join(outputDir, 'index.js'),
|
|
56
|
+
external: [...externalDeps, ...NODE_BUILTIN_MODULES],
|
|
57
|
+
plugins: [resolverPlugin],
|
|
58
|
+
sourcemap: false,
|
|
59
|
+
minify: false,
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
//# sourceMappingURL=bundler.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"bundler.js","sourceRoot":"","sources":["../src/bundler.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,kBAAkB,CAAA;AACtC,OAAO,KAAK,MAAM,MAAM,SAAS,CAAA;AACjC,OAAO,MAAM,MAAM,aAAa,CAAA;AAChC,OAAO,KAAK,IAAI,MAAM,WAAW,CAAA;AACjC,OAAO,KAAK,OAAO,MAAM,SAAS,CAAA;AAElC,OAAO,EAAE,uBAAuB,EAAE,MAAM,uBAAuB,CAAA;AAE/D,MAAM,oBAAoB,GAAG,MAAM,CAAC,cAAc,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,EAAE,QAAQ,CAAC,EAAE,CAAC,CAAC,CAAA;AAEnF,SAAS,cAAc,CAAC,UAAkB,EAAE,WAAoC;IAC9E,MAAM,eAAe,GAAG;QACtB,WAAW,CAAC,MAAM;QAClB,WAAW,CAAC,IAAI;QAChB,cAAc;QACd,cAA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c,CAAC,KAAK,CAAC,IAAI,CAAC,IAAI,EAAE,KAAK,CAAC,IAAI,CAAC,WAAW,CAAC,CAAA;IAC1E,MAAM,YAAY,GAAG,uBAAuB,CAAC,KAAK,CAAC,CAAA;IACnD,MAAM,cAAc,GAAG,0BAA0B,CAAC,KAAK,CAAC,UAAU,CAAC,CAAA;IAEnE,MAAM,EAAE,CAAC,KAAK,CAAC,SAAS,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,CAAA;IAE9C,MAAM,OAAO,CAAC,KAAK,CAAC;QAClB,WAAW,EAAE,CAAC,UAAU,CAAC;QACzB,MAAM,EAAE,IAAI;QACZ,QAAQ,EAAE,MAAM;QAChB,MAAM,EAAE,QAAQ;QAChB,MAAM,EAAE,KAAK;QACb,OAAO,EAAE,IAAI,CAAC,IAAI,CAAC,SAAS,EAAE,UAAU,CAAC;QACzC,QAAQ,EAAE,CAAC,GAAG,YAAY,EAAE,GAAG,oBAAoB,CAAC;QACpD,OAAO,EAAE,CAAC,cAAc,CAAC;QACzB,SAAS,EAAE,KAAK;QAChB,MAAM,EAAE,KAAK;KACd,CAAC,CAAA;AACJ,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"copy-bundler.d.ts","sourceRoot":"","sources":["../src/copy-bundler.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,YAAY,CAAA;AAEjD,wBAAsB,UAAU,CAAC,KAAK,EAAE,eAAe,EAAE,YAAY,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAO/G"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import * as fsPromises from 'node:fs/promises';
|
|
2
|
+
import { buildPackageMap } from './build-package-map.js';
|
|
3
|
+
import { DistCopier } from './dist-copier.js';
|
|
4
|
+
import { ImportRewriter } from './import-rewriter.js';
|
|
5
|
+
export async function copyBundle(graph, monorepoRoot, outputDir) {
|
|
6
|
+
const packageMap = buildPackageMap(graph, monorepoRoot);
|
|
7
|
+
await fsPromises.mkdir(outputDir, { recursive: true });
|
|
8
|
+
const copiedFiles = await new DistCopier(packageMap, outputDir).copy();
|
|
9
|
+
await new ImportRewriter(packageMap, outputDir).rewriteAll(copiedFiles);
|
|
10
|
+
}
|
|
11
|
+
//# sourceMappingURL=copy-bundler.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"copy-bundler.js","sourceRoot":"","sources":["../src/copy-bundler.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,UAAU,MAAM,kBAAkB,CAAA;AAC9C,OAAO,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAA;AACxD,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAA;AAC7C,OAAO,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAA;AAGrD,MAAM,CAAC,KAAK,UAAU,UAAU,CAAC,KAAsB,EAAE,YAAoB,EAAE,SAAiB;IAC9F,MAAM,UAAU,GAAG,eAAe,CAAC,KAAK,EAAE,YAAY,CAAC,CAAA;IAEvD,MAAM,UAAU,CAAC,KAAK,CAAC,SAAS,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,CAAA;IAEtD,MAAM,WAAW,GAAG,MAAM,IAAI,UAAU,CAAC,UAAU,EAAE,SAAS,CAAC,CAAC,IAAI,EAAE,CAAA;IACtE,MAAM,IAAI,cAAc,CAAC,UAAU,EAAE,SAAS,CAAC,CAAC,UAAU,CAAC,WAAW,CAAC,CAAA;AACzE,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"dependency-graph.d.ts","sourceRoot":"","sources":["../src/dependency-graph.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAmB,eAAe,EAAE,MAAM,YAAY,CAAA;AAQlE,wBAAsB,oBAAoB,CAAC,SAAS,EAAE,MAAM,EAAE,YAAY,EAAE,MAAM,GAAG,OAAO,CAAC,eAAe,CAAC,CA4C5G"}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { readPackageJson, discoverMonorepoPackages, isInRepoDep } from './monorepo.js';
|
|
2
|
+
function getDependencies(packageJson) {
|
|
3
|
+
return packageJson.dependencies ?? {};
|
|
4
|
+
}
|
|
5
|
+
export async function buildDependencyGraph(sourceDir, monorepoRoot) {
|
|
6
|
+
const monorepoPackages = await discoverMonorepoPackages(monorepoRoot);
|
|
7
|
+
const packageToBundleJson = readPackageJson(sourceDir);
|
|
8
|
+
const packageToBundle = {
|
|
9
|
+
name: packageToBundleJson.name,
|
|
10
|
+
path: sourceDir,
|
|
11
|
+
packageJson: packageToBundleJson,
|
|
12
|
+
};
|
|
13
|
+
const inRepoDeps = [];
|
|
14
|
+
const allThirdPartyDeps = {};
|
|
15
|
+
const visited = new Set();
|
|
16
|
+
function collectDeps(pkg) {
|
|
17
|
+
if (visited.has(pkg.name)) {
|
|
18
|
+
return;
|
|
19
|
+
}
|
|
20
|
+
visited.add(pkg.name);
|
|
21
|
+
const deps = getDependencies(pkg.packageJson);
|
|
22
|
+
for (const [depName, depVersion] of Object.entries(deps)) {
|
|
23
|
+
if (isInRepoDep(depName, monorepoPackages)) {
|
|
24
|
+
const depPackage = monorepoPackages.get(depName);
|
|
25
|
+
if (depPackage && !visited.has(depName)) {
|
|
26
|
+
inRepoDeps.push(depPackage);
|
|
27
|
+
collectDeps(depPackage);
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
else {
|
|
31
|
+
if (!(depName in allThirdPartyDeps)) {
|
|
32
|
+
allThirdPartyDeps[depName] = depVersion;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
collectDeps(packageToBundle);
|
|
38
|
+
return {
|
|
39
|
+
packageToBundle,
|
|
40
|
+
inRepoDeps,
|
|
41
|
+
allThirdPartyDeps,
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
//# sourceMapping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AU,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,OAAO,CAAC,EAAE,CAAC;oBACxC,UAAU,CAAC,IAAI,CAAC,UAAU,CAAC,CAAA;oBAC3B,WAAW,CAAC,UAAU,CAAC,CAAA;gBACzB,CAAC;YACH,CAAC;iBAAM,CAAC;gBACN,IAAI,CAAC,CAAC,OAAO,IAAI,iBAAiB,CAAC,EAAE,CAAC;oBACpC,iBAAiB,CAAC,OAAO,CAAC,GAAG,UAAU,CAAA;gBACzC,CAAC;YACH,CAAC;QACH,CAAC;IACH,CAAC;IAED,WAAW,CAAC,eAAe,CAAC,CAAA;IAE5B,OAAO;QACL,eAAe;QACf,UAAU;QACV,iBAAiB;KAClB,CAAA;AACH,CAAC"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { PackageMap } from './package-map.js';
|
|
2
|
+
export declare class DistCopier {
|
|
3
|
+
private packageMap;
|
|
4
|
+
private outputDir;
|
|
5
|
+
constructor(packageMap: PackageMap, outputDir: string);
|
|
6
|
+
copy(): Promise<string[]>;
|
|
7
|
+
private collectCopyOperations;
|
|
8
|
+
private copyDir;
|
|
9
|
+
}
|
|
10
|
+
//# sourceMappingURL=dist-copier.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"dist-copier.d.ts","sourceRoot":"","sources":["../src/dist-copier.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAA;AAOlD,qBAAa,UAAU;IAEnB,OAAO,CAAC,UAAU;IAClB,OAAO,CAAC,SAAS;gBADT,UAAU,EAAE,UAAU,EACtB,SAAS,EAAE,MAAM;IAGrB,IAAI,IAAI,OAAO,CAAC,MAAM,EAAE,CAAC;IAS/B,OAAO,CAAC,qBAAqB;YAaf,OAAO;CAgBtB"}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import * as fsPromises from 'node:fs/promises';
|
|
2
|
+
import * as path from 'node:path';
|
|
3
|
+
export class DistCopier {
|
|
4
|
+
packageMap;
|
|
5
|
+
outputDir;
|
|
6
|
+
constructor(packageMap, outputDir) {
|
|
7
|
+
this.packageMap = packageMap;
|
|
8
|
+
this.outputDir = outputDir;
|
|
9
|
+
}
|
|
10
|
+
async copy() {
|
|
11
|
+
const operations = this.collectCopyOperations();
|
|
12
|
+
const copiedFiles = [];
|
|
13
|
+
for (const op of operations) {
|
|
14
|
+
await this.copyDir(op.source, op.destination, copiedFiles);
|
|
15
|
+
}
|
|
16
|
+
return copiedFiles;
|
|
17
|
+
}
|
|
18
|
+
collectCopyOperations() {
|
|
19
|
+
const operations = [];
|
|
20
|
+
for (const location of this.packageMap.values()) {
|
|
21
|
+
operations.push({
|
|
22
|
+
source: location.sourceDistDir,
|
|
23
|
+
destination: path.join(this.outputDir, location.outputDistDir),
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
return operations;
|
|
27
|
+
}
|
|
28
|
+
async copyDir(src, dest, copiedFiles) {
|
|
29
|
+
await fsPromises.mkdir(dest, { recursive: true });
|
|
30
|
+
const entries = await fsPromises.readdir(src, { withFileTypes: true });
|
|
31
|
+
for (const entry of entries) {
|
|
32
|
+
const srcPath = path.join(src, entry.name);
|
|
33
|
+
const destPath = path.join(dest, entry.name);
|
|
34
|
+
if (entry.isDirectory()) {
|
|
35
|
+
await this.copyDir(srcPath, destPath, copiedFiles);
|
|
36
|
+
}
|
|
37
|
+
else {
|
|
38
|
+
await fsPromises.copyFile(srcPath, destPath);
|
|
39
|
+
copiedFiles.push(destPath);
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
//# sourceMappingURL=dist-copier.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"dist-copier.js","sourceRoot":"","sources":["../src/dist-copier.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,UAAU,MAAM,kBAAkB,CAAA;AAC9C,OAAO,KAAK,IAAI,MAAM,WA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C1C,MAAM,QAAQ,GAAG,IAAI,CAAC,IAAI,CAAC,IAAI,EAAE,KAAK,CAAC,IAAI,CAAC,CAAA;YAE5C,IAAI,KAAK,CAAC,WAAW,EAAE,EAAE,CAAC;gBACxB,MAAM,IAAI,CAAC,OAAO,CAAC,OAAO,EAAE,QAAQ,EAAE,WAAW,CAAC,CAAA;YACpD,CAAC;iBAAM,CAAC;gBACN,MAAM,UAAU,CAAC,QAAQ,CAAC,OAAO,EAAE,QAAQ,CAAC,CAAA;gBAC5C,WAAW,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAA;YAC5B,CAAC;QACH,CAAC;IACH,CAAC;CACF"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { PackageMap } from './package-map.js';
|
|
2
|
+
export declare class ImportRewriter {
|
|
3
|
+
private packageMap;
|
|
4
|
+
private outputDir;
|
|
5
|
+
constructor(packageMap: PackageMap, outputDir: string);
|
|
6
|
+
rewriteAll(files: string[]): Promise<void>;
|
|
7
|
+
private rewriteFile;
|
|
8
|
+
private computeNewSpecifier;
|
|
9
|
+
private extractPackageName;
|
|
10
|
+
private computeRelativePath;
|
|
11
|
+
}
|
|
12
|
+
//# sourceMappingURL=import-rewriter.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"import-rewriter.d.ts","sourceRoot":"","sources":["../src/import-rewriter.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAA;AAElD,qBAAa,cAAc;IAEvB,OAAO,CAAC,UAAU;IAClB,OAAO,CAAC,SAAS;gBADT,UAAU,EAAE,UAAU,EACtB,SAAS,EAAE,MAAM;IAGrB,UAAU,CAAC,KAAK,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC;YAOlC,WAAW;IAqDzB,OAAO,CAAC,mBAAmB;IAa3B,OAAO,CAAC,kBAAkB;IAM1B,OAAO,CAAC,mBAAmB;CAQ5B"}
|