@proteinjs/reflection-build 1.5.0 → 2.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.
Files changed (97) hide show
  1. package/CHANGELOG.md +40 -0
  2. package/dist/modules/typescript-parser/declarations/ClassDeclaration.d.ts +1 -0
  3. package/dist/modules/typescript-parser/declarations/ClassDeclaration.js +1 -0
  4. package/dist/modules/typescript-parser/node-parser/class-parser.js +6 -0
  5. package/dist/src/BuildContract.d.ts +69 -0
  6. package/dist/src/BuildContract.js +393 -0
  7. package/dist/src/BuildContract.js.map +1 -0
  8. package/dist/src/ReflectionDoctor.d.ts +95 -0
  9. package/dist/src/ReflectionDoctor.js +588 -0
  10. package/dist/src/ReflectionDoctor.js.map +1 -0
  11. package/dist/src/build.d.ts +5 -1
  12. package/dist/src/build.js +13 -77
  13. package/dist/src/build.js.map +1 -1
  14. package/dist/src/codegen/writeGeneratedIndex.d.ts +18 -0
  15. package/dist/src/codegen/writeGeneratedIndex.js +58 -15
  16. package/dist/src/codegen/writeGeneratedIndex.js.map +1 -1
  17. package/dist/src/parser/createGraphBuilder.js +30 -5
  18. package/dist/src/parser/createGraphBuilder.js.map +1 -1
  19. package/dist/src/parser/types/createClassDeclaration.js +1 -4
  20. package/dist/src/parser/types/createClassDeclaration.js.map +1 -1
  21. package/dist/src/runBuild.js +12 -2
  22. package/dist/src/runBuild.js.map +1 -1
  23. package/dist/src/runDoctor.d.ts +2 -0
  24. package/dist/src/runDoctor.js +83 -0
  25. package/dist/src/runDoctor.js.map +1 -0
  26. package/dist/test/AbstractClassDeclaration.test.d.ts +1 -0
  27. package/dist/test/AbstractClassDeclaration.test.js +121 -0
  28. package/dist/test/AbstractClassDeclaration.test.js.map +1 -0
  29. package/dist/test/GraphEmitRelativePaths.test.d.ts +1 -0
  30. package/dist/test/GraphEmitRelativePaths.test.js +162 -0
  31. package/dist/test/GraphEmitRelativePaths.test.js.map +1 -0
  32. package/dist/test/ReflectionDoctor.test.d.ts +1 -0
  33. package/dist/test/ReflectionDoctor.test.js +316 -0
  34. package/dist/test/ReflectionDoctor.test.js.map +1 -0
  35. package/dist/test/TestSubpathContract.test.d.ts +1 -0
  36. package/dist/test/TestSubpathContract.test.js +260 -0
  37. package/dist/test/TestSubpathContract.test.js.map +1 -0
  38. package/dist/test/ValidateDontMutate.test.d.ts +1 -0
  39. package/dist/test/ValidateDontMutate.test.js +238 -0
  40. package/dist/test/ValidateDontMutate.test.js.map +1 -0
  41. package/dist/test/examples/source-repository/a/generated/index.js +1 -1
  42. package/dist/test/examples/source-repository/a/generated/index.js.map +1 -1
  43. package/dist/test/examples/source-repository/b/generated/index.js +1 -1
  44. package/dist/test/examples/source-repository/b/generated/index.js.map +1 -1
  45. package/modules/typescript-parser/declarations/ClassDeclaration.d.ts +1 -0
  46. package/modules/typescript-parser/declarations/ClassDeclaration.js +1 -0
  47. package/modules/typescript-parser/node-parser/class-parser.js +6 -0
  48. package/package.json +6 -5
  49. package/src/BuildContract.ts +384 -0
  50. package/src/ReflectionDoctor.ts +589 -0
  51. package/src/build.ts +19 -56
  52. package/src/codegen/writeGeneratedIndex.ts +51 -13
  53. package/src/parser/createGraphBuilder.ts +9 -4
  54. package/src/parser/types/createClassDeclaration.ts +5 -5
  55. package/src/runBuild.ts +7 -1
  56. package/src/runDoctor.ts +34 -0
  57. package/test/AbstractClassDeclaration.test.ts +97 -0
  58. package/test/GraphEmitRelativePaths.test.ts +95 -0
  59. package/test/ReflectionDoctor.test.ts +193 -0
  60. package/test/TestSubpathContract.test.ts +148 -0
  61. package/test/ValidateDontMutate.test.ts +126 -0
  62. package/test/examples/source-repository/a/dist/BuildContract.d.ts +69 -0
  63. package/test/examples/source-repository/a/dist/BuildContract.js +393 -0
  64. package/test/examples/source-repository/a/dist/BuildContract.js.map +1 -0
  65. package/test/examples/source-repository/a/dist/build.d.ts +5 -1
  66. package/test/examples/source-repository/a/dist/build.js +13 -77
  67. package/test/examples/source-repository/a/dist/build.js.map +1 -1
  68. package/test/examples/source-repository/a/dist/codegen/writeGeneratedIndex.d.ts +18 -0
  69. package/test/examples/source-repository/a/dist/codegen/writeGeneratedIndex.js +58 -15
  70. package/test/examples/source-repository/a/dist/codegen/writeGeneratedIndex.js.map +1 -1
  71. package/test/examples/source-repository/a/dist/generated/index.js +1 -1
  72. package/test/examples/source-repository/a/dist/generated/index.js.map +1 -1
  73. package/test/examples/source-repository/a/dist/parser/createGraphBuilder.js +30 -5
  74. package/test/examples/source-repository/a/dist/parser/createGraphBuilder.js.map +1 -1
  75. package/test/examples/source-repository/a/dist/parser/types/createClassDeclaration.js +1 -4
  76. package/test/examples/source-repository/a/dist/parser/types/createClassDeclaration.js.map +1 -1
  77. package/test/examples/source-repository/a/dist/runBuild.js +12 -2
  78. package/test/examples/source-repository/a/dist/runBuild.js.map +1 -1
  79. package/test/examples/source-repository/a/generated/index.ts +1 -1
  80. package/test/examples/source-repository/b/dist/BuildContract.d.ts +69 -0
  81. package/test/examples/source-repository/b/dist/BuildContract.js +393 -0
  82. package/test/examples/source-repository/b/dist/BuildContract.js.map +1 -0
  83. package/test/examples/source-repository/b/dist/build.d.ts +5 -1
  84. package/test/examples/source-repository/b/dist/build.js +13 -77
  85. package/test/examples/source-repository/b/dist/build.js.map +1 -1
  86. package/test/examples/source-repository/b/dist/codegen/writeGeneratedIndex.d.ts +18 -0
  87. package/test/examples/source-repository/b/dist/codegen/writeGeneratedIndex.js +58 -15
  88. package/test/examples/source-repository/b/dist/codegen/writeGeneratedIndex.js.map +1 -1
  89. package/test/examples/source-repository/b/dist/generated/index.js +1 -1
  90. package/test/examples/source-repository/b/dist/generated/index.js.map +1 -1
  91. package/test/examples/source-repository/b/dist/parser/createGraphBuilder.js +30 -5
  92. package/test/examples/source-repository/b/dist/parser/createGraphBuilder.js.map +1 -1
  93. package/test/examples/source-repository/b/dist/parser/types/createClassDeclaration.js +1 -4
  94. package/test/examples/source-repository/b/dist/parser/types/createClassDeclaration.js.map +1 -1
  95. package/test/examples/source-repository/b/dist/runBuild.js +12 -2
  96. package/test/examples/source-repository/b/dist/runBuild.js.map +1 -1
  97. package/test/examples/source-repository/b/generated/index.ts +1 -1
@@ -0,0 +1,393 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || function (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
25
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
26
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
27
+ return new (P || (P = Promise))(function (resolve, reject) {
28
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
29
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
30
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
31
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
32
+ });
33
+ };
34
+ var __generator = (this && this.__generator) || function (thisArg, body) {
35
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
36
+ return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
37
+ function verb(n) { return function (v) { return step([n, v]); }; }
38
+ function step(op) {
39
+ if (f) throw new TypeError("Generator is already executing.");
40
+ while (g && (g = 0, op[0] && (_ = 0)), _) try {
41
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
42
+ if (y = 0, t) op = [op[0] & 2, t.value];
43
+ switch (op[0]) {
44
+ case 0: case 1: t = op; break;
45
+ case 4: _.label++; return { value: op[1], done: false };
46
+ case 5: _.label++; y = op[1]; op = [0]; continue;
47
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
48
+ default:
49
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
50
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
51
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
52
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
53
+ if (t[2]) _.ops.pop();
54
+ _.trys.pop(); continue;
55
+ }
56
+ op = body.call(thisArg, _);
57
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
58
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
59
+ }
60
+ };
61
+ Object.defineProperty(exports, "__esModule", { value: true });
62
+ exports.BuildContract = void 0;
63
+ var fs = __importStar(require("fs"));
64
+ var path = __importStar(require("path"));
65
+ var tsconfigTemplate = require('./tsconfigTemplate.json');
66
+ /**
67
+ * The package-config contract of a reflection build (task #104 §3.3, validate-don't-mutate).
68
+ *
69
+ * A build's artifact is only usable if the package's config points at it, so reflection-build
70
+ * owns that config as a contract instead of silently rewriting files on every build:
71
+ *
72
+ * - ABSENT config is completed in place (a fresh or copied package gets main/types, subpath
73
+ * mappings, stubs — the zero-ceremony workflow survives).
74
+ * - EXISTING config that conflicts with the contract fails the build with a friendly error
75
+ * (plain words, why it matters, the exact lines to paste, `--fix` offered first) and leaves
76
+ * every file untouched.
77
+ * - `reflection-build --fix` writes the contract over conflicting values; it is idempotent.
78
+ *
79
+ * Prod builds (primary root 'src') own main/types + the tsconfig include. Subpath builds
80
+ * (primary root e.g. 'test') own the complete subpath contract — root <root>.js/<root>.d.ts
81
+ * stubs, exports/typesVersions mappings, files[] entries, tsconfig excludes (the d51556f0
82
+ * class, generalized): consumers must resolve the subpath to built dist in every install
83
+ * shape and resolution mode, never to sources.
84
+ */
85
+ var BuildContract = /** @class */ (function () {
86
+ function BuildContract(options) {
87
+ this.options = options;
88
+ }
89
+ BuildContract.prototype.apply = function () {
90
+ return __awaiter(this, void 0, void 0, function () {
91
+ var conflicts, writes, _i, writes_1, write;
92
+ return __generator(this, function (_a) {
93
+ conflicts = [];
94
+ writes = [];
95
+ this.applyPackageJson(conflicts, writes);
96
+ this.applyStubs(conflicts, writes);
97
+ this.applyTsconfig(writes);
98
+ if (conflicts.length > 0) {
99
+ throw new Error(this.formatConflicts(conflicts));
100
+ }
101
+ for (_i = 0, writes_1 = writes; _i < writes_1.length; _i++) {
102
+ write = writes_1[_i];
103
+ fs.writeFileSync(write.filePath, write.content);
104
+ }
105
+ return [2 /*return*/];
106
+ });
107
+ });
108
+ };
109
+ BuildContract.prototype.applyPackageJson = function (conflicts, writes) {
110
+ var packageJsonPath = path.join(this.options.packageDir, 'package.json');
111
+ if (!fs.existsSync(packageJsonPath)) {
112
+ throw new Error("package.json does not exist, run `npm init -y` to create one");
113
+ }
114
+ var original = fs.readFileSync(packageJsonPath, 'utf-8');
115
+ var packageJson = JSON.parse(original);
116
+ if (this.isProd()) {
117
+ this.settleEntryPoints(packageJson, conflicts);
118
+ }
119
+ else {
120
+ this.settleSubpathExports(packageJson, conflicts);
121
+ this.settleTypesVersions(packageJson, conflicts);
122
+ this.settleFilesAllowlist(packageJson);
123
+ }
124
+ var updated = JSON.stringify(packageJson, null, 2);
125
+ if (updated !== JSON.stringify(JSON.parse(original), null, 2)) {
126
+ writes.push({ filePath: packageJsonPath, content: updated });
127
+ }
128
+ };
129
+ /** Prod builds: main/types point at the built reflection artifact. */
130
+ BuildContract.prototype.settleEntryPoints = function (packageJson, conflicts) {
131
+ var pasteBlock = [" \"main\": \"".concat(this.prodIndexJs(), "\","), " \"types\": \"".concat(this.prodIndexDts(), "\"")].join('\n');
132
+ var whyItMatters = 'Every consumer loads this package through main/types; pointing them anywhere but the ' +
133
+ 'built reflection artifact ships a package that loads the wrong code.';
134
+ this.settleString(packageJson, 'main', this.prodIndexJs(), conflicts, whyItMatters, pasteBlock);
135
+ this.settleString(packageJson, 'types', this.prodIndexDts(), conflicts, whyItMatters, pasteBlock);
136
+ };
137
+ /** Subpath builds: exports map "." and "./<root>" to the built artifacts. */
138
+ BuildContract.prototype.settleSubpathExports = function (packageJson, conflicts) {
139
+ var _a;
140
+ var root = this.options.primaryRoot;
141
+ var expectedExports = (_a = {
142
+ '.': { types: this.prodIndexDts(), default: this.prodIndexJs() }
143
+ },
144
+ _a["./".concat(root)] = { types: this.subpathIndexDts(), default: this.subpathIndexJs() },
145
+ _a);
146
+ var whyItMatters = "Consumers import '<package>/".concat(root, "' through these mappings; a wrong mapping resolves ") +
147
+ 'to the wrong files (or to sources), breaking consumer builds.';
148
+ if (packageJson.exports == null) {
149
+ packageJson.exports = expectedExports;
150
+ return;
151
+ }
152
+ for (var _i = 0, _b = Object.keys(expectedExports); _i < _b.length; _i++) {
153
+ var subpath = _b[_i];
154
+ var expected = expectedExports[subpath];
155
+ var current = packageJson.exports[subpath];
156
+ if (current == null) {
157
+ packageJson.exports[subpath] = expected;
158
+ }
159
+ else if (JSON.stringify(current) !== JSON.stringify(expected)) {
160
+ if (this.options.fix) {
161
+ packageJson.exports[subpath] = expected;
162
+ }
163
+ else {
164
+ conflicts.push({
165
+ file: 'package.json',
166
+ found: "\"exports\" maps \"".concat(subpath, "\" to ").concat(JSON.stringify(current)),
167
+ expected: JSON.stringify(expected),
168
+ whyItMatters: whyItMatters,
169
+ pasteBlock: " \"exports\": ".concat(JSON.stringify(expectedExports, null, 2).replace(/\n/g, '\n ')),
170
+ });
171
+ }
172
+ }
173
+ }
174
+ };
175
+ /** Subpath builds: typesVersions carries the subpath's types for node10 resolution. */
176
+ BuildContract.prototype.settleTypesVersions = function (packageJson, conflicts) {
177
+ var _a;
178
+ var root = this.options.primaryRoot;
179
+ // No leading './' by typesVersions convention.
180
+ var expected = [this.subpathIndexDts().replace(/^\.\//, '')];
181
+ var expectedBlock = { '*': (_a = {}, _a[root] = expected, _a) };
182
+ if (packageJson.typesVersions == null) {
183
+ packageJson.typesVersions = expectedBlock;
184
+ return;
185
+ }
186
+ if (packageJson.typesVersions['*'] == null) {
187
+ packageJson.typesVersions['*'] = expectedBlock['*'];
188
+ return;
189
+ }
190
+ var current = packageJson.typesVersions['*'][root];
191
+ if (current == null) {
192
+ packageJson.typesVersions['*'][root] = expected;
193
+ }
194
+ else if (JSON.stringify(current) !== JSON.stringify(expected)) {
195
+ if (this.options.fix) {
196
+ packageJson.typesVersions['*'][root] = expected;
197
+ }
198
+ else {
199
+ conflicts.push({
200
+ file: 'package.json',
201
+ found: "\"typesVersions\" maps \"".concat(root, "\" to ").concat(JSON.stringify(current)),
202
+ expected: JSON.stringify(expected),
203
+ whyItMatters: "Editors and node10-resolution consumers find '<package>/".concat(root, "' types through this ") +
204
+ 'mapping; a wrong mapping breaks type resolution for every consumer.',
205
+ pasteBlock: " \"typesVersions\": ".concat(JSON.stringify(expectedBlock, null, 2).replace(/\n/g, '\n ')),
206
+ });
207
+ }
208
+ }
209
+ };
210
+ /** Subpath builds: an existing files allowlist must keep shipping the root stubs. */
211
+ BuildContract.prototype.settleFilesAllowlist = function (packageJson) {
212
+ if (!Array.isArray(packageJson.files)) {
213
+ // No allowlist means npm publishes the stubs already; adding one would change what
214
+ // gets published, which is not this contract's call.
215
+ return;
216
+ }
217
+ for (var _i = 0, _a = [this.stubJsName(), this.stubDtsName()]; _i < _a.length; _i++) {
218
+ var stub = _a[_i];
219
+ if (!packageJson.files.includes(stub)) {
220
+ packageJson.files.push(stub);
221
+ }
222
+ }
223
+ };
224
+ /**
225
+ * Subpath builds: root stubs that win the node10/paths-mapped file lookup, so every install
226
+ * shape resolves the subpath to built dist — never to sources (the TS6059/ts-jest class).
227
+ */
228
+ BuildContract.prototype.applyStubs = function (conflicts, writes) {
229
+ if (this.isProd()) {
230
+ return;
231
+ }
232
+ var root = this.options.primaryRoot;
233
+ var targetNoExt = "./".concat(this.options.distDirRel, "/generated/").concat(root, "/index");
234
+ var whyItMatters = "Consumers compiled with node10/classic resolution (or a tsconfig paths mapping) resolve " +
235
+ "'<package>/".concat(root, "' as a file path, bypassing the exports map; without a root stub that ") +
236
+ 'lands on sources in workspace-symlinked installs (TS6059 breaks the consumer build).';
237
+ var stubJs = {
238
+ file: this.stubJsName(),
239
+ content: "// Node10/classic-resolution stub for the `./".concat(root, "` subpath, owned by reflection-build.\n") +
240
+ "// Consumers that bypass the exports map (node10 resolution, tsconfig paths mappings) resolve\n" +
241
+ "// this file path first, so every install shape loads the built dist \u2014 never sources.\n" +
242
+ "module.exports = require('".concat(targetNoExt, ".js');\n"),
243
+ };
244
+ var stubDts = {
245
+ file: this.stubDtsName(),
246
+ content: "// Types counterpart of ".concat(this.stubJsName(), " \u2014 see that file for why this stub exists.\n") +
247
+ "export * from '".concat(targetNoExt, "';\n"),
248
+ };
249
+ for (var _i = 0, _a = [stubJs, stubDts]; _i < _a.length; _i++) {
250
+ var stub = _a[_i];
251
+ var stubPath = path.join(this.options.packageDir, stub.file);
252
+ if (!fs.existsSync(stubPath)) {
253
+ writes.push({ filePath: stubPath, content: stub.content });
254
+ continue;
255
+ }
256
+ var current = fs.readFileSync(stubPath, 'utf-8');
257
+ if (current.includes(targetNoExt)) {
258
+ continue;
259
+ }
260
+ if (this.options.fix) {
261
+ writes.push({ filePath: stubPath, content: stub.content });
262
+ }
263
+ else {
264
+ conflicts.push({
265
+ file: stub.file,
266
+ found: "".concat(stub.file, " exists but does not point at ").concat(targetNoExt),
267
+ expected: targetNoExt,
268
+ whyItMatters: whyItMatters,
269
+ pasteBlock: stub.content.replace(/^/gm, ' ').trimRight(),
270
+ });
271
+ }
272
+ }
273
+ };
274
+ /**
275
+ * tsconfig: include the generated index; on subpath builds, exclude the root stubs from
276
+ * compilation. List membership only — nothing here can conflict.
277
+ */
278
+ BuildContract.prototype.applyTsconfig = function (writes) {
279
+ var tsconfigPath = path.join(this.options.packageDir, 'tsconfig.json');
280
+ var includePath = "./".concat(path.relative(this.options.packageDir, this.options.generatedIndexPath));
281
+ if (!fs.existsSync(tsconfigPath)) {
282
+ var tsconfig_1 = Object.assign({}, tsconfigTemplate);
283
+ tsconfig_1.include = [includePath];
284
+ if (!this.isProd()) {
285
+ // Fresh exclude must carry node_modules: an explicit exclude replaces the default one.
286
+ tsconfig_1.exclude = ['node_modules', this.stubJsName(), this.stubDtsName()];
287
+ }
288
+ writes.push({ filePath: tsconfigPath, content: JSON.stringify(tsconfig_1, null, 4) });
289
+ return;
290
+ }
291
+ var original = fs.readFileSync(tsconfigPath, 'utf-8');
292
+ var tsconfig = JSON.parse(original);
293
+ if (tsconfig.include && !tsconfig.include.includes(includePath)) {
294
+ tsconfig.include.push(includePath);
295
+ }
296
+ if (!this.isProd()) {
297
+ if (!Array.isArray(tsconfig.exclude)) {
298
+ tsconfig.exclude = ['node_modules'];
299
+ }
300
+ for (var _i = 0, _a = [this.stubJsName(), this.stubDtsName()]; _i < _a.length; _i++) {
301
+ var stub = _a[_i];
302
+ if (!tsconfig.exclude.includes(stub)) {
303
+ tsconfig.exclude.push(stub);
304
+ }
305
+ }
306
+ }
307
+ var updated = JSON.stringify(tsconfig, null, 4);
308
+ if (updated !== JSON.stringify(JSON.parse(original), null, 4)) {
309
+ writes.push({ filePath: tsconfigPath, content: updated });
310
+ }
311
+ };
312
+ /**
313
+ * Settle one string field: absent → set; equal → ok; a dangling value (points at a file
314
+ * that does not exist — npm init's boilerplate `"main": "index.js"`, a stale copy) → set;
315
+ * a value that points at a real, different file is a deliberate setting → conflict.
316
+ */
317
+ BuildContract.prototype.settleString = function (packageJson, field, expected, conflicts, whyItMatters, pasteBlock) {
318
+ var current = packageJson[field];
319
+ if (current === expected) {
320
+ return;
321
+ }
322
+ if (typeof current === 'string' && fs.existsSync(path.join(this.options.packageDir, current))) {
323
+ if (this.options.fix) {
324
+ packageJson[field] = expected;
325
+ }
326
+ else {
327
+ conflicts.push({
328
+ file: 'package.json',
329
+ found: "\"".concat(field, "\" is \"").concat(current, "\""),
330
+ expected: expected,
331
+ whyItMatters: whyItMatters,
332
+ pasteBlock: pasteBlock,
333
+ });
334
+ }
335
+ return;
336
+ }
337
+ packageJson[field] = expected;
338
+ };
339
+ BuildContract.prototype.formatConflicts = function (conflicts) {
340
+ var lines = [];
341
+ lines.push("reflection-build: this package's config conflicts with what the build produces.");
342
+ lines.push("Nothing was changed on disk.");
343
+ lines.push('');
344
+ for (var _i = 0, conflicts_1 = conflicts; _i < conflicts_1.length; _i++) {
345
+ var conflict = conflicts_1[_i];
346
+ lines.push("- ".concat(conflict.file, ": ").concat(conflict.found));
347
+ lines.push(" the build's artifact is ".concat(conflict.expected));
348
+ lines.push(" Why it matters: ".concat(conflict.whyItMatters));
349
+ }
350
+ lines.push('');
351
+ lines.push("The quickest fix \u2014 rewrite just these fields to match the build:");
352
+ lines.push('');
353
+ lines.push(" npx reflection-build --fix");
354
+ lines.push('');
355
+ lines.push("Or paste the expected values in yourself:");
356
+ lines.push('');
357
+ var seen = {};
358
+ for (var _a = 0, conflicts_2 = conflicts; _a < conflicts_2.length; _a++) {
359
+ var conflict = conflicts_2[_a];
360
+ if (seen[conflict.pasteBlock]) {
361
+ continue;
362
+ }
363
+ seen[conflict.pasteBlock] = true;
364
+ lines.push(conflict.pasteBlock);
365
+ lines.push('');
366
+ }
367
+ return lines.join('\n');
368
+ };
369
+ BuildContract.prototype.isProd = function () {
370
+ return this.options.primaryRoot === 'src';
371
+ };
372
+ BuildContract.prototype.prodIndexJs = function () {
373
+ return "./".concat(path.join(this.options.distDirRel, 'generated', 'index.js'));
374
+ };
375
+ BuildContract.prototype.prodIndexDts = function () {
376
+ return "./".concat(path.join(this.options.distDirRel, 'generated', 'index.d.ts'));
377
+ };
378
+ BuildContract.prototype.subpathIndexJs = function () {
379
+ return "./".concat(path.join(this.options.distDirRel, 'generated', this.options.primaryRoot, 'index.js'));
380
+ };
381
+ BuildContract.prototype.subpathIndexDts = function () {
382
+ return "./".concat(path.join(this.options.distDirRel, 'generated', this.options.primaryRoot, 'index.d.ts'));
383
+ };
384
+ BuildContract.prototype.stubJsName = function () {
385
+ return "".concat(this.options.primaryRoot, ".js");
386
+ };
387
+ BuildContract.prototype.stubDtsName = function () {
388
+ return "".concat(this.options.primaryRoot, ".d.ts");
389
+ };
390
+ return BuildContract;
391
+ }());
392
+ exports.BuildContract = BuildContract;
393
+ //# sourceMappingURL=BuildContract.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"BuildContract.js","sourceRoot":"","sources":["../../../../../src/BuildContract.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,qCAAyB;AACzB,yCAA6B;AAC7B,IAAM,gBAAgB,GAAG,OAAO,CAAC,yBAAyB,CAAC,CAAC;AA4B5D;;;;;;;;;;;;;;;;;;GAkBG;AACH;IACE,uBAA6B,OAA6B;QAA7B,YAAO,GAAP,OAAO,CAAsB;IAAG,CAAC;IAExD,6BAAK,GAAX;;;;gBAIQ,SAAS,GAAe,EAAE,CAAC;gBAC3B,MAAM,GAAmB,EAAE,CAAC;gBAClC,IAAI,CAAC,gBAAgB,CAAC,SAAS,EAAE,MAAM,CAAC,CAAC;gBACzC,IAAI,CA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Aa"}
@@ -1 +1,5 @@
1
- export declare function build(): Promise<void>;
1
+ export interface BuildOptions {
2
+ /** Write conflicting package config to the contract instead of failing (reflection-build --fix) */
3
+ fix?: boolean;
4
+ }
5
+ export declare function build(options?: BuildOptions): Promise<void>;
@@ -61,84 +61,16 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
61
61
  Object.defineProperty(exports, "__esModule", { value: true });
62
62
  exports.build = void 0;
63
63
  var path = __importStar(require("path"));
64
- var tsconfig = require('./tsconfigTemplate.json');
65
- var util_node_1 = require("@proteinjs/util-node");
66
64
  var writeGeneratedIndex_1 = require("./codegen/writeGeneratedIndex");
67
- function build() {
65
+ var BuildContract_1 = require("./BuildContract");
66
+ function build(options) {
67
+ if (options === void 0) { options = {}; }
68
68
  return __awaiter(this, void 0, void 0, function () {
69
- // TODO save their index location in package.json and pass it in to writeGeneratedIndex above
70
- function updatePackageJson() {
71
- return __awaiter(this, void 0, void 0, function () {
72
- var targetDirPackageJson, targetPackageJson, originalPackageJsonString, isProd, targetDirDist, relGenPath, targetDirDistGenerated, generatedIndexJs, generatedIndexDts, updatedPackageJsonString;
73
- return __generator(this, function (_a) {
74
- switch (_a.label) {
75
- case 0:
76
- targetDirPackageJson = path.join(targetDir, 'package.json');
77
- return [4 /*yield*/, util_node_1.promisifiedFs.exists(targetDirPackageJson)];
78
- case 1:
79
- if (!(_a.sent())) {
80
- throw new Error("package.json does not exist, run `npm init -y` to create one");
81
- }
82
- targetPackageJson = require(targetDirPackageJson);
83
- originalPackageJsonString = JSON.stringify(targetPackageJson, null, 2);
84
- isProd = primaryRoot === 'src';
85
- if (isProd) {
86
- targetDirDist = path.join(targetDir, distDirRel);
87
- relGenPath = primaryRoot && primaryRoot !== 'src'
88
- ? path.relative(targetDir, path.join(targetDir, 'generated', primaryRoot))
89
- : path.relative(targetDir, path.join(targetDir, 'generated'));
90
- targetDirDistGenerated = path.join(targetDirDist, relGenPath);
91
- generatedIndexJs = path.join(targetDirDistGenerated, 'index.js');
92
- generatedIndexDts = path.join(targetDirDistGenerated, 'index.d.ts');
93
- targetPackageJson.main = "./".concat(path.relative(targetDir, generatedIndexJs));
94
- targetPackageJson.types = "./".concat(path.relative(targetDir, generatedIndexDts));
95
- }
96
- updatedPackageJsonString = JSON.stringify(targetPackageJson, null, 2);
97
- if (!(originalPackageJsonString !== updatedPackageJsonString)) return [3 /*break*/, 3];
98
- return [4 /*yield*/, util_node_1.promisifiedFs.writeFile(targetDirPackageJson, updatedPackageJsonString)];
99
- case 2:
100
- _a.sent();
101
- _a.label = 3;
102
- case 3: return [2 /*return*/];
103
- }
104
- });
105
- });
106
- }
107
- function writeTsconfig() {
108
- return __awaiter(this, void 0, void 0, function () {
109
- var existingTsconfig, includePath, generatedTsconfig;
110
- return __generator(this, function (_a) {
111
- switch (_a.label) {
112
- case 0: return [4 /*yield*/, util_node_1.promisifiedFs.exists(targetDirTsconfig)];
113
- case 1:
114
- if (!_a.sent()) return [3 /*break*/, 4];
115
- existingTsconfig = require(targetDirTsconfig);
116
- includePath = "./".concat(path.relative(targetDir, generatedIndex));
117
- if (!(existingTsconfig.include && !existingTsconfig.include.includes(includePath))) return [3 /*break*/, 3];
118
- existingTsconfig.include.push(includePath);
119
- return [4 /*yield*/, util_node_1.promisifiedFs.writeFile(targetDirTsconfig, JSON.stringify(existingTsconfig, null, 4))];
120
- case 2:
121
- _a.sent();
122
- _a.label = 3;
123
- case 3: return [3 /*break*/, 6];
124
- case 4:
125
- generatedTsconfig = Object.assign({}, tsconfig);
126
- generatedTsconfig.include = ["./".concat(path.relative(targetDir, generatedIndex))];
127
- return [4 /*yield*/, util_node_1.promisifiedFs.writeFile(targetDirTsconfig, JSON.stringify(generatedTsconfig, null, 4))];
128
- case 5:
129
- _a.sent();
130
- _a.label = 6;
131
- case 6: return [2 /*return*/];
132
- }
133
- });
134
- });
135
- }
136
- var targetDir, targetDirTsconfig, sourceRootsRaw, sourceRoots, primaryRoot, publicEntryRelOverride, distDirRel, targetDirGenerated, generatedIndex;
69
+ var targetDir, sourceRootsRaw, sourceRoots, primaryRoot, publicEntryRelOverride, distDirRel, targetDirGenerated, generatedIndex, contract;
137
70
  return __generator(this, function (_a) {
138
71
  switch (_a.label) {
139
72
  case 0:
140
73
  targetDir = process.env.INIT_CWD;
141
- targetDirTsconfig = path.join(targetDir, 'tsconfig.json');
142
74
  sourceRootsRaw = (process.env.REFLECTION_SOURCE_DIRS || '')
143
75
  .split(',')
144
76
  .map(function (s) { return s.trim(); })
@@ -151,14 +83,18 @@ function build() {
151
83
  ? path.join(targetDir, 'generated', primaryRoot)
152
84
  : path.join(targetDir, 'generated');
153
85
  generatedIndex = path.join(targetDirGenerated, 'index.ts');
154
- return [4 /*yield*/, updatePackageJson()];
86
+ contract = new BuildContract_1.BuildContract({
87
+ packageDir: targetDir,
88
+ primaryRoot: primaryRoot,
89
+ distDirRel: distDirRel,
90
+ generatedIndexPath: generatedIndex,
91
+ fix: !!options.fix,
92
+ });
93
+ return [4 /*yield*/, contract.apply()];
155
94
  case 1:
156
- _a.sent();
157
- return [4 /*yield*/, writeTsconfig()];
158
- case 2:
159
95
  _a.sent();
160
96
  return [4 /*yield*/, (0, writeGeneratedIndex_1.writeGeneratedIndex)(targetDir, targetDirGenerated, generatedIndex, sourceRoots, publicEntryRelOverride)];
161
- case 3:
97
+ case 2:
162
98
  _a.sent();
163
99
  return [2 /*return*/];
164
100
  }
@@ -1 +1 @@
1
- {"version":3,"file":"build.js","sourceRoot":"","sources":["../../../../../src/build.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,yCAA6B;AAC7B,IAAM,QAAQ,GAAG,OAAO,CAAC,yBAAyB,CAAC,CAAC;AACpD,kDAAqD;AACrD,qEAAoE;AAEpE,SAAsB,KAAK;;QAoCzB,6FAA6F;QAC7F,SAAe,iBAAiB;;;;;;4BACxB,oBAAoB,GAAG,IAAI,CAAC,IAAI,CAAC,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AAE,CAAC,CAAC,OAAO,CAAC,GAAG;qBACnB,CAAC,CAAC;oBACH,qBAAM,QAAQ,CAAC,KAAK,EAAE,EAAA;;oBAAtB,SAAsB,CAAC;oBAEvB,qBAAM,IAAA,yCAAmB,EAAC,SAAS,EAAE,kBAAkB,EAAE,cAAc,EAAE,WAAW,EAAE,sBAAsB,CAAC,EAAA;;oBAA7G,SAA6G,CAAC;;;;;CAC/G;AA5CD,sBA4CC"}
@@ -1,3 +1,4 @@
1
+ import { Graph } from '@dagrejs/graphlib';
1
2
  /**
2
3
  * @param packageDir Root of the package (contains package.json)
3
4
  * @param packageGeneratedDir Directory where generated/index.ts will be written
@@ -15,3 +16,20 @@ export declare function writeGeneratedIndex(packageDir: string, packageGenerated
15
16
  * and correct for workspace symlinks (the symlinked package root carries its own dist).
16
17
  */
17
18
  export declare function dependencyHasSourceGraph(packageDir: string, packageName: string): boolean;
19
+ /**
20
+ * Full path to the dependency's source-graph artifact, or undefined when the dependency is
21
+ * not installed or not reflection-built. Same walk as `dependencyHasSourceGraph`; exposed for
22
+ * static graph harvesting (reflection-doctor).
23
+ */
24
+ export declare function findDependencySourceGraph(packageDir: string, packageName: string): string | undefined;
25
+ /**
26
+ * The installed location of a dependency, resolved by walking `node_modules` up from the
27
+ * consuming package — npm-layout resolution: the nearest installed copy shadows hoisted ones.
28
+ */
29
+ export declare function findDependencyDir(packageDir: string, packageName: string): string | undefined;
30
+ /**
31
+ * The graph exactly as a build emits it: parsed from the package's source roots, with
32
+ * build-time-non-loadable declarations pruned. Owned here so build emit and diagnostic
33
+ * tooling (reflection-doctor drift checks) share one pipeline.
34
+ */
35
+ export declare function createEmittedSourceGraph(packageDir: string, sourceRootsRel: string[]): Promise<Graph>;