@@ -2,10 +2,12 @@ import { createRsbuild } from '@rsbuild/core';
22import { createRslib } from '@rslib/core' ;
33import { expect , it } from '@rstest/core' ;
44import { init , parse } from 'es-module-lexer/minimal' ;
5+ import { execFile } from 'node:child_process' ;
56import { mkdir , mkdtemp , readFile , readdir , symlink , writeFile } from 'node:fs/promises' ;
67import { isBuiltin } from 'node:module' ;
78import { tmpdir } from 'node:os' ;
89import { join } from 'node:path' ;
10+ import { promisify } from 'node:util' ;
911
1012import { composeMcpAppsRsbuildConfig } from '../src/build/mcp-apps.ts' ;
1113import { buildWithRslib } from '../src/build/compiler.ts' ;
@@ -14,7 +16,6 @@ import {
1416 compilerHostNodeFloor ,
1517 composeEntryLibConfig ,
1618 entryLibId ,
17- generatedExecutableLegalComments ,
1819 generatedExecutableSyntax ,
1920 type RslibEntry ,
2021} from '../src/build/rslib.ts' ;
@@ -55,10 +56,17 @@ const selfContainedProject = async (): Promise<{ readonly entry: RslibEntry; rea
5556 await mkdir ( join ( root , 'views' ) , { recursive : true } ) ;
5657 await writeFile ( join ( root , 'package.json' ) , '{"type":"module"}\n' ) ;
5758 await symlink ( agentBundleNodeModules , join ( root , 'node_modules' ) , 'dir' ) ;
59+ await writeFile ( join ( root , 'src' , 'licensed.js' ) , [
60+ '/*! licensed-probe v1.0.0 | MIT License */' ,
61+ '/** Probe documentation that must not reach the artifact. */' ,
62+ "export const licensed = () => 'licensed-probe';" ,
63+ '' ,
64+ ] . join ( '\n' ) ) ;
5865 await writeFile ( join ( root , 'src' , 'entry.ts' ) , [
5966 "import { basename } from 'node:path';" ,
6067 "import { parse } from 'yaml';" ,
61- "console.log(basename('/probe/config.yaml'), parse('probe: true'));" ,
68+ "import { licensed } from './licensed.js';" ,
69+ "console.log(JSON.stringify([basename('/probe/config.yaml'), parse('probe: true'), licensed()]));" ,
6270 '' ,
6371 ] . join ( '\n' ) ) ;
6472 await writeFile ( join ( root , 'views' , 'dashboard.ts' ) , "document.title = 'dashboard';\n" ) ;
@@ -117,15 +125,6 @@ it('derives generated-executable syntax from the compiler host floor matching en
117125 expect ( lib . syntax ) . toBe ( generatedExecutableSyntax ) ;
118126} ) ;
119127
120- it ( 'reserves inline legal comments for future minification without adding a license asset today' , ( ) => {
121- expect ( generatedExecutableLegalComments ) . toBe ( 'inline' ) ;
122- const root = join ( tmpdir ( ) , 'agent-bundle-legal-comments-profile' ) ;
123- const lib = composeEntryLibConfig ( probeEntry ( root ) , { cwd : root , meta : testMeta , outputRoot : join ( root , 'dist' ) } ) ;
124- expect ( lib . output ?. legalComments ) . toBe ( generatedExecutableLegalComments ) ;
125- expect ( lib . output ?. minify ) . toBe ( false ) ;
126- expect ( lib . output ?. sourceMap ) . toBe ( false ) ;
127- } ) ;
128-
129128it ( 'opts generated-executable source maps in through output.sourceMap' , ( ) => {
130129 const root = join ( tmpdir ( ) , 'agent-bundle-source-map-profile' ) ;
131130 const entry = probeEntry ( root ) ;
@@ -140,7 +139,8 @@ it('opts generated-executable source maps in through output.sourceMap', () => {
140139} ) ;
141140
142141it ( 'lowers a generated executable with only Node builtins external and inlines its dependencies' , async ( ) => {
143- const { entry, root } = await selfContainedProject ( ) ;
142+ const { entry : probe , root } = await selfContainedProject ( ) ;
143+ const entry : RslibEntry = { ...probe , banner : '#!/usr/bin/env node' } ;
144144 const inspections : RslibInspection [ ] = [ ] ;
145145 try {
146146 await buildWithRslib ( { cwd : root , entries : [ entry ] , meta : testMeta , outputRoot : join ( root , 'dist' ) } , {
@@ -189,6 +189,13 @@ it('lowers a generated executable with only Node builtins external and inlines i
189189 expect ( specifiers . filter ( ( specifier ) => specifier === undefined || ! isBuiltin ( specifier ) ) ) . toEqual ( [ ] ) ;
190190 expect ( bundle ) . toContain ( 'YAMLParseError' ) ;
191191 expect ( bundle ) . toMatch ( / c r e a t e R e q u i r e \( i m p o r t \. m e t a \. u r l \) / u) ;
192+ expect ( bundle . startsWith ( '#!/usr/bin/env node\n' ) ) . toBe ( true ) ;
193+ expect ( bundle ) . toContain ( '\nvar __webpack_modules__ = {\n' ) ;
194+ expect ( bundle ) . toContain ( '/*! licensed-probe v1.0.0 | MIT License */' ) ;
195+ expect ( bundle ) . not . toContain ( 'Probe documentation that must not reach the artifact.' ) ;
196+ expect ( bundle ) . not . toContain ( 'Parse the input as a stream of YAML documents.' ) ;
197+ const { stdout } = await promisify ( execFile ) ( process . execPath , [ join ( root , 'dist' , 'scripts' , 'probe.mjs' ) ] ) ;
198+ expect ( JSON . parse ( stdout ) ) . toEqual ( [ 'config.yaml' , { probe : true } , 'licensed-probe' ] ) ;
192199 await expect ( readdir ( join ( root , 'dist' ) ) ) . resolves . toEqual ( [ 'scripts' ] ) ;
193200 await expect ( readdir ( join ( root , 'dist' , 'scripts' ) ) ) . resolves . toEqual ( [ 'probe.mjs' ] ) ;
194201 } finally {
0 commit comments