fix(sdk): scan template literal imports

This commit is contained in:
2026-09-05 08:24:11 +08:00
parent 88784ad52a
commit 2570dd7b97
2 changed files with 41 additions and 3 deletions
@@ -242,6 +242,30 @@ test('scanner resolves and rejects an sdk runtime path alias into framework impl
assert.match(violations[0].message, /sdk.*framework implementation.*framework\/core/);
});
test('scanner resolves and rejects a no-substitution-template dynamic sdk path alias', async () => {
const root = await createFixtureRoot();
await writeFixture(root, 'framework/core/internal.ts', 'export const value = true\n');
await writeFixture(
root,
'framework/sdk/runtime/nested/bad.ts',
'void import(`@framework/core/internal`)\n',
);
await writeFixture(root, 'tsconfig.json', JSON.stringify({
compilerOptions: {
baseUrl: '.',
paths: { '@framework/*': ['framework/*'] },
module: 'ESNext',
moduleResolution: 'Bundler',
allowImportingTsExtensions: true,
},
}));
const violations = scan(root, 'tsconfig.json');
assert.equal(violations.length, 1);
assert.equal(violations[0].specifier, '@framework/core/internal');
assert.match(violations[0].message, /sdk.*framework implementation.*framework\/core/);
});
test('scanner rejects Cocos imports throughout sdk runtime', async () => {
for (const specifier of ['cc', 'cc/env']) {
const root = await createFixtureRoot();
@@ -258,6 +282,20 @@ test('scanner rejects Cocos imports throughout sdk runtime', async () => {
}
});
test('scanner rejects a no-substitution-template dynamic Cocos import in nested sdk code', async () => {
const root = await createFixtureRoot();
await writeFixture(
root,
'framework/sdk/testing/nested/bad.ts',
'void import(`cc/env`)\n',
);
const violations = scan(root);
assert.equal(violations.length, 1);
assert.equal(violations[0].specifier, 'cc/env');
assert.match(violations[0].message, /sdk.*Cocos/);
});
test('sdk migration barrel exception permits only its four retained legacy dependencies', async () => {
const root = await createFixtureRoot();
for (const file of [