@@ -309,6 +309,56 @@ describe('Require Path Resolution', () => {
309309 expect ( pageModule . code ) . not . toContain ( 'require("/miniprogram_npm/westore/root")' )
310310 } )
311311
312+ it ( 'should resolve crypto-js bare package requires via package entry' , async ( ) => {
313+ fs . mkdirSync ( 'miniprogram_npm/crypto-js' , { recursive : true } )
314+
315+ fs . writeFileSync ( 'app.json' , JSON . stringify ( {
316+ pages : [ 'pages/crypto/index' ]
317+ } ) )
318+
319+ fs . mkdirSync ( 'pages/crypto' , { recursive : true } )
320+ fs . writeFileSync ( 'miniprogram_npm/crypto-js/package.json' , JSON . stringify ( {
321+ main : 'index.js'
322+ } ) )
323+ fs . writeFileSync ( 'miniprogram_npm/crypto-js/index.js' , `
324+ module.exports = {
325+ enc: {
326+ Utf8: {
327+ parse(value) {
328+ return value
329+ }
330+ }
331+ }
332+ }
333+ ` )
334+
335+ fs . writeFileSync ( 'pages/crypto/index.js' , `
336+ const CryptoJS = require('crypto-js')
337+
338+ Page({
339+ onLoad() {
340+ console.log(CryptoJS.enc.Utf8.parse('hello'))
341+ }
342+ })
343+ ` )
344+
345+ fs . writeFileSync ( 'pages/crypto/index.json' , JSON . stringify ( {
346+ navigationBarTitleText : 'Crypto'
347+ } ) )
348+
349+ storeInfo ( tempDir )
350+
351+ const progress = { completedTasks : 0 }
352+ const result = await compileJS ( [ { path : 'pages/crypto/index' } ] , null , null , progress )
353+
354+ const modulePaths = result . map ( module => module . path )
355+ expect ( modulePaths ) . toContain ( '/miniprogram_npm/crypto-js/index' )
356+
357+ const pageModule = result . find ( module => module . path === 'pages/crypto/index' )
358+ expect ( pageModule . code ) . toContain ( 'require("/miniprogram_npm/crypto-js/index")' )
359+ expect ( pageModule . code ) . not . toContain ( 'require("/crypto-js")' )
360+ } )
361+
312362 it ( 'should handle mixed import and require statements' , async ( ) => {
313363 // 创建测试文件结构
314364 fs . mkdirSync ( 'pages/mixed' , { recursive : true } )
0 commit comments