mirror of
https://github.com/bilawalsidhu/gods-eye-view.git
synced 2026-11-16 16:22:20 +00:00
build: reach Navara only through import() and ship its worker wasm
The import-direction check now tells dynamic imports apart
(analyzeModule(source, { dynamic: true })) and rejects any static import
or re-export of src/globe/navara/** from outside that directory, so the
Navara engine can only be a lazily loaded chunk of the app.
Navara's prebuilt workers load their wasm by file name next to
themselves, which the bundler cannot see; a build-only Rollup plugin
copies the missing ones (draco decoder, font worker) into assets/ when
the bundle includes Navara, and adds nothing to a build without it.
This commit is contained in:
1 parent
72fec292d4
commit
306e3e9467
8 files changed
+179
-7
No files matched your search
@@ -241,6 +241,44 @@ for (const [name, files, pattern] of [
|
||||
});
|
||||
}
|
||||
|
||||
test('module analysis can tell dynamic imports from static ones', () => {
|
||||
assert.deepEqual(
|
||||
analyzeModule(
|
||||
"import a from 'one'; export * from 'two'; import('three'); const x = () => import('four');",
|
||||
{ dynamic: true },
|
||||
),
|
||||
{
|
||||
imports: ['one', 'two', 'three', 'four'],
|
||||
browser: [],
|
||||
dynamicImports: ['three', 'four'],
|
||||
},
|
||||
);
|
||||
});
|
||||
|
||||
test('the app reaches the Navara engine only through a dynamic import', (t) => {
|
||||
const { root, write } = fixture(t);
|
||||
write('src/globe/navara/index.js', "import './engine.js';");
|
||||
write('src/globe/navara/engine.js', '');
|
||||
write(
|
||||
'src/app/scene.js',
|
||||
"export const load = () => import('../globe/navara/index.js');",
|
||||
);
|
||||
assert.doesNotThrow(() => checkImportDirections(root));
|
||||
write('src/app/scene.js', "import '../globe/navara/index.js';");
|
||||
assert.throws(
|
||||
() => checkImportDirections(root),
|
||||
/src\/app\/scene\.js: The Navara engine loads only through a dynamic import\(\): src\/globe\/navara\/index\.js/,
|
||||
);
|
||||
write(
|
||||
'src/app/scene.js',
|
||||
"export { createNavaraGlobe } from '../globe/navara/index.js';",
|
||||
);
|
||||
assert.throws(
|
||||
() => checkImportDirections(root),
|
||||
/only through a dynamic import/,
|
||||
);
|
||||
});
|
||||
|
||||
test('geo modules may import each other, and its tests may import cesium', (t) => {
|
||||
const { root, write } = fixture(t);
|
||||
write('src/geo/math.js', 'export const half = (value) => value / 2;');
|
||||
|
||||
Reference in new issue
Block a user