-
Notifications
You must be signed in to change notification settings - Fork 72
Expand file tree
/
Copy path.monorepolint.config.mjs
More file actions
1606 lines (1515 loc) · 52 KB
/
Copy path.monorepolint.config.mjs
File metadata and controls
1606 lines (1515 loc) · 52 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
* Copyright 2024 Palantir Technologies, Inc. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
// @ts-check
import * as child_process from "node:child_process";
import fs from "node:fs/promises";
import path from "node:path";
import { fileURLToPath } from "node:url";
import { archetypes, ifTrue } from "@monorepolint/archetypes";
import {
alphabeticalDependencies,
alphabeticalScripts,
createRuleFactory,
fileContents,
packageEntry,
packageOrder,
packageScript,
requireDependency,
standardTsconfig,
} from "@monorepolint/rules";
import * as semver from "semver";
const rootPackageJson = JSON.parse(
await fs.readFile(
path.join(path.dirname(fileURLToPath(import.meta.url)), "package.json"),
"utf-8",
),
);
const LATEST_TYPESCRIPT_DEP = "~5.5.4";
const DELETE_SCRIPT_ENTRY = { options: [undefined], fixValue: undefined };
const OUTPUT_NORMAL =
/** @type {const} */ ({ browser: "normal", cjs: "bundle", esm: "normal" });
const OUTPUT_BUNDLE_ALL =
/** @type {const} */ ({ browser: "bundle", cjs: "bundle", esm: "bundle" });
const OUTPUT_ESM_ONLY =
/** @type {const} */ ({ browser: undefined, cjs: undefined, esm: "normal" });
/** @type {OsdkPackageOptions} */
const LIBRARY_RULES = {
tsVersion: LATEST_TYPESCRIPT_DEP,
repositoryUrl: "https://github.com/palantir/osdk-ts.git",
output: OUTPUT_NORMAL,
private: false,
aliasConsola: false,
};
/** @type {OsdkPackageOptions} */
const INTERNAL_LIBRARY_RULES = {
...LIBRARY_RULES,
output: OUTPUT_ESM_ONLY,
skipAttw: true,
private: true,
};
const archetypeRules = archetypes(standardPackageRules, {
unmatched: "error",
})
.addArchetype("clientPackage", ["@osdk/client"], {
...LIBRARY_RULES,
checkApi: true,
typecheckProject: "tsconfig.typecheck.json",
// Migrated to the oxc toolchain (oxlint + oxfmt). Carries a nested oxlint
// config (oxcConfig) holding behavior-preserving carve-outs for the
// error-level Ultracite rules this hand-written package first surfaces.
oxc: true,
oxcConfig: "./oxlint.config.ts",
})
.addArchetype(
"tests and benchmarks",
["@osdk/tests.*", "@osdk/benchmarks.*"],
{
...LIBRARY_RULES,
minimalChangesOnly: true,
private: true,
},
)
.addArchetype(
"minimal packages",
[
// @osdk/e2e.generated.1.1.x migrated to the oxc toolchain (it joins "oxc
// migrated minimal packages" below).
"@osdk/examples.*",
"@psdk/examples.*",
"@osdk/monorepo.*",
],
{
...LIBRARY_RULES,
minimalChangesOnly: true,
private: true,
},
)
.addArchetype(
"standardLibraries",
[
// The generator packages stay on ESLint (generators are excluded from the oxc
// migration). The vite-plugin-* packages migrated to the oxc toolchain (they
// join "oxc migrated libraries with carve-outs" below).
"@osdk/generator-converters",
"@osdk/generator-converters.ontologyir",
"@osdk/generator-converters.preview",
"@osdk/generator-utils",
"@osdk/generator",
],
{
...LIBRARY_RULES,
},
)
.addArchetype(
"consumerCliPackages",
[
// @osdk/cli, @osdk/create-app, and @osdk/create-widget migrated to the oxc
// toolchain (see "oxc migrated consumer clis" below); @osdk/foundry-sdk-generator
// is a generator package and stays on ESLint.
"@osdk/foundry-sdk-generator",
],
{
...LIBRARY_RULES,
output: {
browser: undefined,
cjs: undefined,
esm: "bundle",
},
fixedDepsOnly: true,
},
)
.addArchetype("consumerCliWithSite", ["@osdk/ontology-explorer-server"], {
...LIBRARY_RULES,
output: {
browser: undefined,
cjs: undefined,
esm: "bundle",
},
fixedDepsOnly: true,
extraPublishFiles: ["build/site"],
// Migrated to the oxc toolchain; carries a nested oxlint config for the
// error-level Ultracite rules its source first surfaces.
oxc: true,
oxcConfig: "./oxlint.config.ts",
})
.addArchetype(
"internal clis",
[
// @osdk/create-app.template-packager, @osdk/tool.*, and @osdk/version-updater
// migrated to the oxc toolchain (see "oxc migrated internal clis" below); the
// *-generator packages stay on ESLint (generators are excluded from the oxc
// migration).
"@osdk/example-generator",
"@osdk/typescript-docs-example-generator",
"@osdk/osdk-docs-context-generator",
],
{
...INTERNAL_LIBRARY_RULES,
skipTypes: true,
},
)
// Internal libraries / templates migrated to the oxc toolchain. Split by whether
// the package's source first surfaces error-level Ultracite rules the prior
// ESLint config did not enforce: those that do carry a nested oxlint config
// (oxcConfig) turning them off; those that do not lint against the root config.
.addArchetype(
"oxc migrated internal libraries / templates with carve-outs",
["@osdk/cli.*", "@osdk/shared.test", "@osdk/shared.test.intellisense"],
{
...INTERNAL_LIBRARY_RULES,
oxc: true,
oxcConfig: "./oxlint.config.ts",
},
)
.addArchetype(
"oxc migrated internal libraries / templates",
[
"@osdk/client.test.ontology",
// These are the create-app / create-widget template *packages* (their own
// 1-file src). The shipped scaffolding under each package's templates/ dir is
// ignored by oxlint + oxfmt and migrates separately.
"@osdk/create-app.react.beta.common",
"@osdk/create-app.template.*",
"@osdk/create-widget.template.*",
],
{
...INTERNAL_LIBRARY_RULES,
oxc: true,
},
)
// Consumer CLIs migrated to the oxc toolchain (from consumerCliPackages; same
// esm-bundle output + fixedDepsOnly options). Each surfaces error-level Ultracite
// rules the prior ESLint config did not enforce, so each carries a nested config.
.addArchetype(
"oxc migrated consumer clis",
["@osdk/cli", "@osdk/create-app", "@osdk/create-widget"],
{
...LIBRARY_RULES,
output: {
browser: undefined,
cjs: undefined,
esm: "bundle",
},
fixedDepsOnly: true,
oxc: true,
oxcConfig: "./oxlint.config.ts",
},
)
// Internal CLIs migrated to the oxc toolchain (from internal clis; same
// INTERNAL_LIBRARY_RULES + skipTypes options). Each surfaces error-level Ultracite
// rules the prior ESLint config did not enforce, so each carries a nested config.
.addArchetype(
"oxc migrated internal clis",
[
"@osdk/create-app.template-packager",
"@osdk/tool.*",
"@osdk/version-updater",
],
{
...INTERNAL_LIBRARY_RULES,
skipTypes: true,
oxc: true,
oxcConfig: "./oxlint.config.ts",
},
)
// Packages migrated to the oxc toolchain (oxlint + oxfmt). As more packages
// are migrated, add them here (taking care not to capture generated
// namespace-prefix children via monorepolint's archetype matching).
//
// TODO: these "oxc migrated ..." archetypes are transitional. Once every
// package is on the oxc toolchain (the final flip in #3031), oxc becomes the
// default and the "migrated" distinction disappears — collapse these back into
// the base library archetypes and drop the `oxc: true` / `oxcConfig` plumbing.
.addArchetype(
"oxc migrated libraries",
[
"@osdk/language-models",
"@osdk/react-sdk-docs",
"@osdk/shared.client.impl",
"@osdk/shared.net.errors",
"@osdk/shared.net.fetch",
"@osdk/shared.net",
"@osdk/typescript-sdk-docs",
"@osdk/widget.api",
"@osdk/widget.client",
],
{
...LIBRARY_RULES,
oxc: true,
},
)
// Same as "oxc migrated libraries" but with a nested oxlint config (oxcConfig)
// holding behavior-preserving carve-outs. The maker family is hand-written and
// first surfaces a set of error-level Ultracite rules the prior ESLint config
// did not enforce; each package's oxlint.config.ts `extends` the root and turns
// them off so the migration is a reformat, not a rewrite.
.addArchetype(
"oxc migrated libraries with carve-outs",
[
"@osdk/maker",
"@osdk/maker-experimental",
"@osdk/maker-import",
"@osdk/aip-core",
"@osdk/foundry-config-json",
"@osdk/seed-compiler",
"@osdk/seed-helpers",
"@osdk/oauth",
"@osdk/faux",
"@osdk/osdk-docs-context",
// vite-plugin-* packages (migrated from standardLibraries): plain
// LIBRARY_RULES like the standard libraries, each surfacing error-level rules
// the prior ESLint config did not enforce, so each carries a nested config.
"@osdk/vite-plugin-oac",
"@osdk/vite-plugin-superrepo",
"@osdk/vite-plugin-status-reporter",
"@osdk/vite-plugin-code-workspace-preview",
"@osdk/vite-plugin-branch",
],
{
...LIBRARY_RULES,
oxc: true,
oxcConfig: "./oxlint.config.ts",
},
)
// Same as "oxc migrated libraries with carve-outs" but additionally carries
// checkApi (API Extractor reports). These are the core published API-surface
// packages (@osdk/api is the core SDK type surface) that previously lived in
// the checkApiPackages archetype before being migrated to the oxc toolchain.
// Each first surfaces error-level Ultracite rules the prior ESLint config did
// not enforce, so each carries a nested oxlint config (oxcConfig) turning them
// off to keep the migration a reformat, not a rewrite.
.addArchetype(
"oxc migrated libraries with check-api",
["@osdk/api", "@osdk/functions", "@osdk/agents", "@osdk/unit-testing"],
{
...LIBRARY_RULES,
oxc: true,
checkApi: true,
oxcConfig: "./oxlint.config.ts",
},
)
.addArchetype(
"oxc migrated libraries with check-api and a postinstall script",
["@osdk/integration-testing"],
{
...LIBRARY_RULES,
oxc: true,
checkApi: true,
oxcConfig: "./oxlint.config.ts",
extraPublishFiles: ["bin/postinstall.mjs"],
},
)
// React packages migrated to the oxc toolchain. Same as "oxc migrated
// libraries" but with `react: true` (happy-dom vitest env + react tsconfig).
// @osdk/widget.client-react is the first React package on oxc, validating
// the Ultracite React preset for the rest of the repo.
.addArchetype("oxc migrated react libraries", ["@osdk/widget.client-react"], {
...LIBRARY_RULES,
react: true,
oxc: true,
})
// React packages with CSS exports migrated to the oxc toolchain. Same as
// "oxc migrated react libraries" but additionally carries the cssExport,
// extraPublishFiles, and setupFiles options. @osdk/cbac-components is the
// first React package with CSS exports on oxc, validating the cssExport
// archetype path ahead of @osdk/react-components.
.addArchetype(
"oxc migrated react libraries with css",
["@osdk/cbac-components"],
{
...LIBRARY_RULES,
react: true,
oxc: true,
cssExport: ["styles.css"],
extraPublishFiles: ["AGENTS.md", "docs"],
setupFiles: ["./src/test/setupPolyfills.ts"],
},
)
// React package with bundled docs migrated to the oxc toolchain. Same as
// "oxc migrated react libraries" but additionally carries the extraPublishFiles
// and customTsconfigExcludes options. @osdk/react is the React family's core
// hooks package.
.addArchetype("oxc migrated react libraries with docs", ["@osdk/react"], {
...LIBRARY_RULES,
react: true,
oxc: true,
extraPublishFiles: ["AGENTS.md", "docs", "experimental"],
customTsconfigExcludes: ["./src/intellisense.test.helpers/**"],
})
// ESM-only React package with CSS exports migrated to the oxc toolchain. Same
// as "oxc migrated react libraries with css" but ESM-only output and without
// the extra publish/setup files. @osdk/react-devtools.
.addArchetype(
"oxc migrated esm react libraries with css",
["@osdk/react-devtools"],
{
...LIBRARY_RULES,
react: true,
oxc: true,
output: OUTPUT_ESM_ONLY,
cssExport: ["styles.css"],
},
)
// Private, minimal-change packages migrated to the oxc toolchain. Mirrors the
// "minimal packages" archetype (minimalChangesOnly + private) but on oxc.
// @osdk/react-components-storybook is the storybook for
// @osdk/react-components; its lint scripts are not monorepolint-managed (see
// minimalPackageRules), so they are set directly in its package.json.
.addArchetype(
"oxc migrated minimal packages",
[
"@osdk/react-components-storybook",
// e2e.generated.1.1.x (migrated from "minimal packages"): a generated SDK
// fixture; its one hand-written index surfaces no error-level rules, so it
// lints against the root config (its scripts are hand-set, see below).
"@osdk/e2e.generated.1.1.x",
],
{
...LIBRARY_RULES,
minimalChangesOnly: true,
private: true,
oxc: true,
},
)
// Force-bundle libraries migrated to the oxc toolchain. Same as "oxc migrated
// libraries" but carry OUTPUT_BUNDLE_ALL (bundled cjs/esm/browser), which is
// what the former forceBundle archetype provided (now removed; both its members
// live here). @osdk/client.unstable and @osdk/client.unstable.tpsa are both
// almost entirely conjure-generated code under src/generated; this repo treats
// that as first-class checked-in source (ESLint + dprint processed it before
// the migration), so each carries a nested oxlint config (oxcConfig) that
// re-includes the generated tree and turns off the few error-level rules it
// surfaces, keeping the migration behavior-preserving. The generated tree is
// also oxfmt-formatted via the root oxfmt.config.ts (which no longer ignores
// `**/generated`).
.addArchetype(
"oxc migrated force-bundle libraries with carve-outs",
["@osdk/client.unstable", "@osdk/client.unstable.tpsa"],
{
...LIBRARY_RULES,
output: OUTPUT_BUNDLE_ALL,
oxc: true,
oxcConfig: "./oxlint.config.ts",
},
)
.addArchetype(
"internal libraries / templates with modern tooling ES2023",
["@osdk/typescript-sdk-docs-examples"],
{
...INTERNAL_LIBRARY_RULES,
extraTsConfigCompilerOptions: {
lib: ["ES2023", "DOM", "ESNEXT.Array"],
},
// Migrated to the oxc toolchain (oxlint + oxfmt). Its `codegen` step
// reformats freshly-generated documentation examples via `pnpm run format`
// (now oxfmt), and oxfmt can't run on Node < 20.19/22.18. This is safe on
// CI: the test-matrix leg is the only step that runs on the older Node
// versions (every other job runs on Node 24), and on those legs codegen is
// restored from the Node-24 build cache rather than re-executed (see #3783),
// so its oxfmt format step never runs there.
oxc: true,
oxcConfig: "./oxlint.config.ts",
},
)
.addArchetype("publishedSandboxes", ["@osdk/e2e.sandbox.catchall"], {
...INTERNAL_LIBRARY_RULES,
skipTypes: true,
private: false,
extraFiles: ["src/"],
skipBuildInFiles: true,
// Migrated to the oxc toolchain; carries a nested oxlint config for the
// error-level Ultracite rules its source first surfaces.
oxc: true,
oxcConfig: "./oxlint.config.ts",
})
.addArchetype("publishedGeneratedSdks", ["@osdk/e2e.generated.catchall"], {
...LIBRARY_RULES,
skipAttw: true,
extraExports: {
"./experimental/ontology-metadata": {
import: {
types:
"./build/types/generatedNoCheck/experimental/ontology-metadata.d.mts",
default:
"./build/esm/generatedNoCheck/experimental/ontology-metadata.json",
},
require: {
types:
"./build/types/generatedNoCheck/experimental/ontology-metadata.d.cts",
default:
"./build/esm/generatedNoCheck/experimental/ontology-metadata.json",
},
},
},
// Migrated to the oxc toolchain; carries a nested oxlint config (its
// src/index.ts barrel re-exports the generated ontology, tripping
// oxc/no-barrel-file once the module graph is resolvable).
oxc: true,
oxcConfig: "./oxlint.config.ts",
})
.addArchetype(
"currentlyGeneratedSdks",
["@osdk/e2e.generated.api-namespace.*"],
{
...LIBRARY_RULES,
skipAttw: true,
private: true,
// Migrated to the oxc toolchain; carries a nested oxlint config (one member's
// hand-written index surfaces an error-level rule the prior ESLint did not
// enforce).
oxc: true,
oxcConfig: "./oxlint.config.ts",
},
)
.addArchetype(
"viteSandboxes",
[
"@osdk/e2e.sandbox.officeassignment",
"@osdk/e2e.sandbox.officenetwork",
"@osdk/e2e.sandbox.todowidget",
"@osdk/e2e.sandbox.todoapp",
"@osdk/e2e.sandbox.peopleapp",
"@osdk/e2e.sandbox.oauth.public.react-router",
],
{
...INTERNAL_LIBRARY_RULES,
skipTypes: true,
react: true,
extraTsConfigCompilerOptions: {
isolatedDeclarations: false,
},
// Migrated to the oxc toolchain; each carries a nested oxlint config for the
// error-level Ultracite rules its source first surfaces (including the
// license-header carve-out the prior ESLint config applied to e2e.sandbox.*).
oxc: true,
oxcConfig: "./oxlint.config.ts",
},
)
.addArchetype("viteReactAppsWithScss", ["@osdk/ontology-explorer-app"], {
...INTERNAL_LIBRARY_RULES,
skipTypes: true,
react: true,
extraTsConfigCompilerOptions: {
isolatedDeclarations: false,
plugins: [{ name: "typescript-plugin-css-modules" }],
rootDirs: ["./src", "./build/scss-types"],
allowArbitraryExtensions: true,
},
// Migrated to the oxc toolchain; carries a nested oxlint config for the
// error-level Ultracite rules its source first surfaces. Its .scss/.css are
// left to their authors (oxfmt ignores them).
oxc: true,
oxcConfig: "./oxlint.config.ts",
})
.addArchetype("nodeSandboxes", ["@osdk/e2e.sandbox.oauth"], {
...INTERNAL_LIBRARY_RULES,
skipTypes: true,
// Migrated to the oxc toolchain; surfaces no error-level rules, so it lints
// against the root config.
oxc: true,
})
.addArchetype("e2eTests", ["@osdk/e2e.test.foundry-sdk-generator"], {
...INTERNAL_LIBRARY_RULES,
output: OUTPUT_NORMAL,
skipTypes: true,
// Migrated to the oxc toolchain; carries a nested oxlint config for the
// error-level Ultracite rules its source first surfaces.
oxc: true,
oxcConfig: "./oxlint.config.ts",
})
.addArchetype("vitePlugin", ["@osdk/widget.vite-plugin"], {
...LIBRARY_RULES,
react: true,
output: OUTPUT_ESM_ONLY,
extraPublishFiles: ["build/site"],
// Migrated to the oxc toolchain (deferred from the widget batch for churn);
// carries a nested oxlint config for the error-level Ultracite rules its
// source first surfaces.
oxc: true,
oxcConfig: "./oxlint.config.ts",
})
// The 221-tsx component-library giant migrated to the oxc toolchain. Same
// options as the former "reactComponentsLibrary" archetype (react + cssExport
// + extraPublishFiles + the full experimental/* attw exclude list + the test
// setup/env/pool) plus `oxc: true`. Its package-specific carve-outs live in a
// nested oxlint config (packages/react-components/oxlint.config.ts, which
// `extends` the root), so `oxcConfig` points lint/fix-lint at that file rather
// than the root config.
.addArchetype(
"oxc migrated react components library",
["@osdk/react-components"],
{
...LIBRARY_RULES,
react: true,
oxc: true,
oxcConfig: "./oxlint.config.ts",
cssExport: ["styles.css"],
extraPublishFiles: ["AGENTS.md", "docs"],
attwExcludeEntrypoints: [
"./experimental/action-form",
"./experimental/aip-agent-chat",
"./experimental/cbac-picker",
"./experimental/document-viewer",
"./experimental/email-viewer",
"./experimental/filter-list",
"./experimental/image-viewer",
"./experimental/markdown-renderer",
"./experimental/object-table",
"./experimental/pdf-viewer",
"./experimental/spreadsheet-viewer",
"./experimental/theme",
"./experimental/tiff-renderer",
"./experimental/video-viewer",
"./experimental/xml-viewer",
],
setupFiles: ["./src/test/setupPolyfills.ts"],
vitestEnv: {
TZ: "UTC",
LANG: "en_US.UTF-8",
},
vitestPool: "threads",
},
)
.addArchetype("docs", ["@osdk/docs"], {
...LIBRARY_RULES,
minimalChangesOnly: true,
private: true,
});
/**
* We don't want to allow `workspace:^` in our regular dependencies because our current release
* branch strategy only allows for patch changes in the release branch and minors elsewhere.
*
* If we were to allow `workspace:^`, then the follow scenario causes issues:
* - Suppose we have a Foo and a Bar package and Bar depends on Foo.
* - at T0 we cut a release/1.1.x branch and ship Foo@1.1.0, Bar@1.1.0
* - at T1 we cut a release 1.2.x branch and ship Foo@1.2.0
*
* If we have `workspace:^` in our deps, a user that already has `Bar@1.1.0` in their package.json
* could update their dependencies without updating Bar (say via pnpm update) and Bar's dependency
* on Foo @ `^1.1.0` would be satisfied by the shipped `Foo@1.2.0`.
*
* Using `workspace:~` prevents this as `~` can only resolve patch changes.
*
* However, peerDependencies are the exception: they MUST use `workspace:^`. With `workspace:~`,
* a minor bump in a peer dep (e.g. @osdk/api 2.8.0 -> 2.9.0) falls outside the tilde range
* (`~2.8.0`), so changesets treats it as a breaking change and forces a major bump on the
* consuming package. Using `workspace:^` keeps minor bumps in range (`^2.8.0` accepts `2.9.0`).
* Additionally, this is how most of our public packages with peer dependencies are treated. They
* should be compatible with any higher version of the dependency, and anything else would be a break
* for users.
* See: https://github.com/palantir/osdk-ts/pull/3020
*/
const disallowWorkspaceCaret = createRuleFactory({
name: "disallowWorkspaceCaret",
check: async (context) => {
const packageJson = context.getPackageJson();
const packageJsonPath = context.getPackageJsonPath();
for (const d of ["dependencies", "devDependencies", "peerDependencies"]) {
const deps = packageJson[d] ?? {};
for (const [dep, version] of Object.entries(deps)) {
if (dep === "@osdk/shared.client2") {
const expected = "^1.0.0";
if (version !== expected) {
const message = `${dep} may only have '${expected}'`;
context.addError({
message,
longMessage: message,
file: context.getPackageJsonPath(),
fixer: () => {
// always refetch in fixer since another fixer may have already changed the file
const packageJson = context.getPackageJson();
if (packageJson[d]) {
packageJson[d] = {
...packageJson[d],
[dep]: expected,
};
context.host.writeJson(
context.getPackageJsonPath(),
packageJson,
);
}
},
});
}
} else if (d === "peerDependencies" && version === "workspace:~") {
const message =
`'workspace:~' not allowed in peerDependencies (${d}['${dep}']).`;
context.addError({
message,
longMessage:
`${message} Use 'workspace:^' for peerDependencies to avoid major bumps when peer deps receive minor version changes.`,
file: context.getPackageJsonPath(),
fixer: () => {
const packageJson = context.getPackageJson();
if (packageJson[d]?.[dep] === "workspace:~") {
packageJson[d] = {
...packageJson[d],
[dep]: "workspace:^",
};
context.host.writeJson(
context.getPackageJsonPath(),
packageJson,
);
}
},
});
} else if (version === "workspace:^" && d !== "peerDependencies") {
if (
dep === "@osdk/shared.client2"
// Since this package is only being used internally, it's fine to keep this relaxed to ^ so it can use newer client versions without bumping everything
|| (packageJson.name === "@osdk/functions"
&& dep === "@osdk/client")
) {
continue;
}
const message = `'workspace:^' not allowed (${d}['${dep}']).`;
context.addError({
message,
longMessage: `${message} Did you mean 'workspace:~'?`,
file: context.getPackageJsonPath(),
fixer: () => {
// always refetch in fixer since another fixer may have already changed the file
const packageJson = context.getPackageJson();
if (packageJson[d]?.[dep] === "workspace:^") {
packageJson[d] = {
...packageJson[d],
[dep]: "workspace:~",
};
context.host.writeJson(
context.getPackageJsonPath(),
packageJson,
);
}
},
});
}
}
}
},
validateOptions: () => {}, // no options right now
});
// We hit that fun fun bug where foundry-sdk-generator ended up getting packaged with a newer version
// of typescript which broke code formatting. This rule is to make sure we don't experience that again.
// (note devDeps are only happening at buildtime so they should be fine)
const fixedDepsOnly = createRuleFactory({
name: "fixedDepsOnly",
check: async (context) => {
const packageJson = context.getPackageJson();
for (const d of ["dependencies", "peerDependencies"]) {
const deps = packageJson[d] ?? {};
for (const [dep, version] of Object.entries(deps)) {
if (version === "workspace:*") continue;
if (version === "catalog:foundry-platform-typescript") continue;
if (version[0] >= "0" && version[0] <= "9") continue;
if (dep === "typescript" && version[0] === "~") continue;
if (dep === "rollup" && version[0] === "^") continue; // we want rollup CVE fixes
const message =
`May only have fixed dependencies (found ${d}['${dep}'] == '${version}').`;
context.addError({
message,
longMessage: message,
file: context.getPackageJsonPath(),
});
}
}
},
validateOptions: () => {}, // no options right now
});
/**
* @type {import("@monorepolint/rules").RuleFactoryFn<{entries: string[]}>}
*/
const noPackageEntry = createRuleFactory({
name: "noPackageEntry",
check: async (context, options) => {
const packageJson = context.getPackageJson();
for (const entry of options.entries) {
if (packageJson[entry]) {
context.addError({
message: `${entry} field is not allowed`,
longMessage: `${entry} field is not allowed`,
file: context.getPackageJsonPath(),
});
}
}
},
validateOptions: (options) => {
return (
typeof options === "object"
&& "entries" in options
&& Array.isArray(options.entries)
);
},
});
/**
* @param {string} dirPath
*/
async function dirExists(dirPath) {
try {
const stat = await fs.stat(dirPath);
return stat.isDirectory();
} catch {
return false;
}
}
/**
* @type {import("@monorepolint/rules").RuleFactoryFn< {
* browser?: boolean,
* cjs?: boolean,
* cssExports?: string[],
* extraExports?: Record<string, unknown>
* }>}
*/
const ourExportsConvention = createRuleFactory({
name: "ourExportsConvention",
check: async (context, options) => {
context.getPackageJson();
context.packageDir;
// FIXME: use context.host once mrl learns to read dirs
const publicPath = path.join(context.packageDir, "src", "public");
const expectedExports = {
exports: {
".": {
browser: options.browser ? "./build/browser/index.js" : undefined,
import: {
// we generate the types for this in a separate task
// than transpile so they end up in different places
types: "./build/types/index.d.ts",
default: "./build/esm/index.js",
},
// for cjs, we generate the types next to the transpiled code
// so we don't need to separate anything out. TSC infers properly
require: options.cjs ? "./build/cjs/index.cjs" : undefined,
default: `./build/${options.browser ? "browser" : "esm"}/index.js`,
},
},
};
function makeExport(fileName) {
return {
...(options.browser
? { browser: `./build/browser/public/${fileName}.js` }
: {}),
import: {
types: `./build/types/public/${fileName}.d.ts`,
default: `./build/esm/public/${fileName}.js`,
},
...(options.cjs
? { require: `./build/cjs/public/${fileName}.cjs` }
: {}),
default: `./build/${
options.browser ? "browser" : "esm"
}/public/${fileName}.js`,
};
}
if (await dirExists(publicPath)) {
for (
const q of await fs.readdir(publicPath, {
withFileTypes: true,
encoding: "utf-8",
recursive: true,
})
) {
if (!q.isFile()) continue;
if (!q.name.endsWith(".ts")) continue;
const fullPath = path.join(q.parentPath, q.name);
const rel = path.relative(publicPath, fullPath);
const b = rel.replace(/\.ts$/, "");
expectedExports.exports[`./${b}`] = makeExport(b);
}
}
// add CSS exports if any (must come before the wildcard)
const cssDir = options.browser ? "build/browser" : "build/esm";
for (const cssFile of options.cssExports ?? []) {
expectedExports.exports[`./${cssFile}`] = `./${cssDir}/${cssFile}`;
}
// escape hatch for subpaths this convention can't derive from src/public,
// e.g. generated data assets. also must come before the wildcard.
for (
const [subpath, target] of Object.entries(
options.extraExports ?? {},
)
) {
expectedExports.exports[subpath] = target;
}
// include the fallback for the * for now, as it will make development easier
// must come last or it will override the others
expectedExports.exports["./*"] = makeExport("*");
await packageEntry({
options: {
entries: {
exports: expectedExports.exports,
},
},
}).check(context);
},
validateOptions: () => {},
});
const allLocalDepsMustNotBePrivate = createRuleFactory({
name: "allLocalDepsMustNotBePrivate",
check: async (context) => {
const packageJson = context.getPackageJson();
const deps = packageJson.dependencies ?? {};
const nameToDir = await context.getWorkspaceContext().getPackageNameToDir();
for (const [dep, version] of Object.entries(deps)) {
if (nameToDir.has(dep)) {
const packageDir = nameToDir.get(dep);
/** @type any */
const theirPackageJson = context.host.readJson(
path.join(packageDir, "package.json"),
);
if (theirPackageJson.private) {
const message =
`${dep} is private and cannot be used as a regular dependency for this package`;
context.addError({
message,
longMessage: message,
file: context.getPackageJsonPath(),
});
}
}
}
},
validateOptions: () => {}, // no options right now
});
const setWorkspaceDepRangeForPrereleases = createRuleFactory({
name: "setWorkspaceDepRangeForPrereleases",
check: async (context) => {
const packageJson = context.getPackageJson();
const packageJsonPath = context.getPackageJsonPath();
if (packageJson.name !== "@osdk/client") return;
if (!packageJson.version) {
context.addError({
message: "package.json is missing a version field",
file: packageJsonPath,
});
return;
}
const packageJsonVersion = String(packageJson.version) ?? "";
const isPrerelease = !!semver.prerelease(packageJsonVersion);
const depField = "dependencies";
const depName = "@osdk/api";
if (depName in packageJson.dependencies) {
const current = packageJson.dependencies[depName];
const expected = isPrerelease ? "workspace:*" : "workspace:~";
if (current !== expected) {
context.addError({
message: `@osdk/client is ${
isPrerelease ? "a prerelease" : "stable"
}, so its dependency on @osdk/api should be '${expected}', found '${current}'`,
longMessage:
`Set dependencies['${depName}'] to '${expected}' in @osdk/client (currently version ${packageJson.version})`,
file: packageJsonPath,
fixer: () => {
const updated = context.getPackageJson();
if (updated[depField]?.[depName] === current) {
updated[depField][depName] = expected;
context.host.writeJson(packageJsonPath, updated);
}
},
});
}
}
},
validateOptions: () => {},
});
const cache = new Map();
/**
* @param {string} contents
*/
const formattedGeneratorHelper = (contents, ext) => async (context) => {
if (cache.has(contents)) {
return cache.get(contents);
}
const result = child_process.spawnSync(
`pnpm exec dprint fmt --stdin foo.${ext}`,
{
input: contents,
encoding: "utf-8",
shell: true,
},
);
if (result.error) {
throw result.error;
}
cache.set(contents, result.stdout);
return result.stdout;