11// @effect -diagnostics nodeBuiltinImport:off - Tests exercise the Node filesystem build boundary.
22
33import * as NodeFSP from "node:fs/promises" ;
4+ import * as NodeChildProcess from "node:child_process" ;
45import * as NodeOS from "node:os" ;
56import * as NodePath from "node:path" ;
67import * as NodeURL from "node:url" ;
78
8- import { DEVICE_TOOL_VERSIONS } from "@t3tools/shared/deviceToolVersions" ;
99import { afterEach , describe , expect , it } from "vite-plus/test" ;
1010
1111import {
@@ -19,6 +19,12 @@ const REPOSITORY_ROOT = NodePath.resolve(
1919 NodePath . dirname ( NodeURL . fileURLToPath ( import . meta. url ) ) ,
2020 "../.." ,
2121) ;
22+ const DEVICE_TOOL_VERSIONS = JSON . parse (
23+ await NodeFSP . readFile (
24+ NodePath . join ( REPOSITORY_ROOT , "apps/server/src/device/deviceToolVersions.json" ) ,
25+ "utf8" ,
26+ ) ,
27+ ) as { readonly "agent-device" : string ; readonly "expo-device-hub" : string } ;
2228
2329async function writeJson ( path : string , value : unknown ) : Promise < void > {
2430 await NodeFSP . mkdir ( NodePath . dirname ( path ) , { recursive : true } ) ;
@@ -78,6 +84,77 @@ afterEach(async () => {
7884} ) ;
7985
8086describe ( "third-party license generation" , ( ) => {
87+ it ( "generates mobile notices without scripts workspace dependency links" , async ( ) => {
88+ const fixture = await createFixture ( ) ;
89+ const generatorPath = NodePath . join ( fixture . root , "scripts/lib/third-party-licenses.ts" ) ;
90+ const versionsPath = NodePath . join (
91+ fixture . root ,
92+ "apps/server/src/device/deviceToolVersions.json" ,
93+ ) ;
94+ await Promise . all ( [
95+ NodeFSP . mkdir ( NodePath . dirname ( generatorPath ) , { recursive : true } ) ,
96+ NodeFSP . mkdir ( NodePath . dirname ( versionsPath ) , { recursive : true } ) ,
97+ ] ) ;
98+ await Promise . all ( [
99+ writeJson ( NodePath . join ( fixture . root , "scripts/package.json" ) , { type : "module" } ) ,
100+ NodeFSP . copyFile (
101+ NodePath . join ( REPOSITORY_ROOT , "scripts/lib/third-party-licenses.ts" ) ,
102+ generatorPath ,
103+ ) ,
104+ NodeFSP . copyFile (
105+ NodePath . join ( REPOSITORY_ROOT , "apps/server/src/device/deviceToolVersions.json" ) ,
106+ versionsPath ,
107+ ) ,
108+ writeJson ( fixture . configFile , {
109+ customNotices : Object . keys ( DEVICE_TOOL_VERSIONS ) . map ( ( name ) => ( {
110+ name,
111+ license : "MIT" ,
112+ noticeFile : "asset-notice.txt" ,
113+ bundles : [ "device-tools" ] ,
114+ includeInBundles : [ "mobile" , "web" ] ,
115+ } ) ) ,
116+ } ) ,
117+ ] ) ;
118+
119+ const output = NodeChildProcess . execFileSync (
120+ process . execPath ,
121+ [
122+ "--input-type=module" ,
123+ "--eval" ,
124+ `
125+ import { pathToFileURL } from "node:url";
126+ const { generateThirdPartyLicenseManifest } = await import(
127+ pathToFileURL(process.argv[1]).href + "?version=1"
128+ );
129+ const manifest = await generateThirdPartyLicenseManifest({
130+ configFile: process.argv[2],
131+ packageManifests: [{ bundle: "mobile", path: process.argv[3] }],
132+ });
133+ process.stdout.write(JSON.stringify(manifest));
134+ ` ,
135+ generatorPath ,
136+ fixture . configFile ,
137+ fixture . appManifest ,
138+ ] ,
139+ { cwd : fixture . root , encoding : "utf8" } ,
140+ ) ;
141+ const manifest = JSON . parse ( output ) as {
142+ entries : ReadonlyArray < { name : string ; version : string } > ;
143+ } ;
144+ expect ( manifest . entries ) . toEqual (
145+ expect . arrayContaining ( [
146+ expect . objectContaining ( {
147+ name : "agent-device" ,
148+ version : DEVICE_TOOL_VERSIONS [ "agent-device" ] ,
149+ } ) ,
150+ expect . objectContaining ( {
151+ name : "expo-device-hub" ,
152+ version : DEVICE_TOOL_VERSIONS [ "expo-device-hub" ] ,
153+ } ) ,
154+ ] ) ,
155+ ) ;
156+ } ) ;
157+
81158 it . each ( [ "web" , "mobile" ] ) (
82159 "uses installer pins for device tool notices in the %s manifest" ,
83160 async ( bundle ) => {
0 commit comments