chore: cleanup

This commit is contained in:
Nathan Walker
2025-07-22 19:06:58 -07:00
parent 0ba0ab0d59
commit b853447da2
16 changed files with 162 additions and 179 deletions

View File

@@ -12,7 +12,7 @@ export default function (config: Config, env: IWebpackEnv = _env): Config {
const entryPath = getEntryPath();
const virtualEntryPath = path.resolve(
__dirname,
'../stubs/virtual-entry-typescript.js'
`../stubs/virtual-entry-typescript.${env.commonjs ? 'js' : 'mjs'}`,
);
// exclude files starting with _ from require.context
@@ -23,7 +23,7 @@ export default function (config: Config, env: IWebpackEnv = _env): Config {
chainedSetAddAfter(
config.entry('bundle'),
'@nativescript/core/globals/index',
virtualEntryPath
virtualEntryPath,
);
config.when(env.hmr, (config) => {

View File

@@ -1,5 +1,5 @@
// VIRTUAL ENTRY START
require('@nativescript/core/bundle-entry-points')
const context = require.context("~/", /* deep: */ true, /* filter: */ /.(xml|js|s?css)$/);
global.registerWebpackModules(context);
global.registerBundlerModules(context);
// VIRTUAL ENTRY END

View File

@@ -1,5 +1,5 @@
// VIRTUAL ENTRY START
require('@nativescript/core/bundle-entry-points')
const context = require.context("~/", /* deep: */ true, /* filter: */ /\.(xml|js|(?<!\.d\.)ts|s?css)$/);
global.registerWebpackModules(context);
global.registerBundlerModules(context);
// VIRTUAL ENTRY END

View File

@@ -0,0 +1,78 @@
// VIRTUAL ENTRY START
require('@nativescript/core/bundle-entry-points')
import { readdirSync } from 'fs';
import { join, extname, relative } from 'path';
import { fileURLToPath } from 'url';
import { createRequire } from 'module';
console.log('__COMMONJS__:', __COMMONJS__);
// const context = require.context("~/", /* deep: */ true, /* filter: */ /\.(xml|js|(?<!\.d\.)ts|s?css)$/);
// const modules = import.meta.glob(
// // adjust the pattern to your layout:
// "/src/**/*.@(xml|js|ts|scss|css)"
// // { eager: true } // uncomment to import immediately
// );
console.log('typeof import.meta.glob:', typeof import.meta.glob);
if (typeof import.meta.glob !== 'undefined') {
// Vite environment
const modules = import.meta.glob(
// adjust the pattern to your layout:
'~/**/*.@(xml|js|ts|scss|css)',
{ eager: true }, // uncomment to import immediately
);
global.registerBundlerModules(modules);
} else {
const require = createRequire(import.meta.url);
const root = fileURLToPath(new URL('./src', import.meta.url));
/**
* Recursively walk `dir`, collecting all files whose extension is in `exts`,
* ignoring any `*.d.ts` files.
*/
function collectFilesSync(
dir,
exts = ['.xml', '.js', '.ts', '.css', '.scss'],
) {
let results = [];
for (const entry of readdirSync(dir, { withFileTypes: true })) {
const full = join(dir, entry.name);
if (entry.isDirectory()) {
results = results.concat(collectFilesSync(full, exts));
} else {
// skip declaration files
if (entry.name.endsWith('.d.ts')) continue;
// filter by extension
if (exts.includes(extname(entry.name))) {
results.push(full);
}
}
}
return results;
}
/**
* Synchronously load every matching module under `./src`,
* keyed by its path relative to `root`.
*/
function loadContextSync() {
const files = collectFilesSync(root);
const context = {};
for (const fullPath of files) {
// make the key look like fastglobs relative paths
const relPath = relative(root, fullPath).replace(/\\/g, '/');
// require() each module
context[relPath] = require(fullPath);
}
return context;
}
const context = loadContextSync();
global.registerBundlerModules(context);
}
// VIRTUAL ENTRY END