From 4fe0003eb67b734ea60509047fd5d2113b626211 Mon Sep 17 00:00:00 2001 From: Nathan Walker Date: Mon, 14 Jul 2025 08:47:45 -0700 Subject: [PATCH] chore: tmp comments to verify loading order - cleanup after confirmed --- packages/core/globals/index.ts | 35 ++++++------------------ packages/core/profiling/index.ts | 5 +++- packages/core/ui/styling/style-scope.ts | 26 ++++++++++++++---- packages/core/utils/native-helper.ios.ts | 8 +++++- 4 files changed, 40 insertions(+), 34 deletions(-) diff --git a/packages/core/globals/index.ts b/packages/core/globals/index.ts index 236988d8f..86db819ab 100644 --- a/packages/core/globals/index.ts +++ b/packages/core/globals/index.ts @@ -12,6 +12,12 @@ import * as wgc from '../wgc'; import * as cryptoImpl from '../wgc/crypto'; import * as subtleCryptoImpl from '../wgc/crypto/SubtleCrypto'; +console.log('here in globals/index!'); +console.log(`typeof __dirname:`, typeof __dirname); +// commonjs builds will have __dirname defined, but es6 modules will not +global.__dirname = typeof __dirname !== 'undefined' ? __dirname : import.meta.dirname; +console.log('global.__dirname', global.__dirname); + if (typeof global.__metadata === 'undefined') { /** * TS decorator metadata helper. @@ -408,34 +414,11 @@ function isTestingEnv() { return typeof jest !== 'undefined' || global.__UNIT_TEST__; } -if (typeof global.__metadata === 'undefined') { - /** - * TS decorator metadata helper. - * @param metadataKey the metadata key (e.g. "design:type") - * @param metadataValue the metadata value (e.g. the constructor function) - * @returns a decorator function, or undefined if Reflect.metadata isn’t available - */ - global.__metadata = (metadataKey, metadataValue) => { - if ( - typeof Reflect === 'object' && - // @ts-expect-error - typeof Reflect.metadata === 'function' - ) { - // Delegate to the reflect-metadata shim - // @ts-expect-error - return Reflect.metadata(metadataKey, metadataValue); - } - // no-op if no Reflect.metadata - }; -} - +console.log('global.NativeScriptHasInitGlobal:', global.NativeScriptHasInitGlobal); +console.log('isTestingEnv():', isTestingEnv()); if (!global.NativeScriptHasInitGlobal && !isTestingEnv()) { initGlobal(); } -// if (!isTestingEnv()) { -// // ensure the Application instance is initialized before any other module imports it. -// require('@nativescript/core/application'); -// } // ensure the Application instance is initialized before any other module imports it. -import '@nativescript/core/application'; +import '../application'; diff --git a/packages/core/profiling/index.ts b/packages/core/profiling/index.ts index d549bd878..d0b893048 100644 --- a/packages/core/profiling/index.ts +++ b/packages/core/profiling/index.ts @@ -1,3 +1,5 @@ +// @ts-ignore apps resolve this at runtime with path alias in project bundlers +import appConfig from '~/package.json'; /* eslint-disable prefer-rest-params */ declare let __startCPUProfiler: any; declare let __stopCPUProfiler: any; @@ -158,8 +160,9 @@ export function enable(mode: InstrumentationMode = 'counters') { } try { + // const appConfig = require('~/package.json'); // @ts-ignore - const appConfig = await import('~/package.json'); + // const appConfig = await import('~/package.json'); console.log('profiling appConfig:', appConfig); if (appConfig && appConfig.profiling) { enable(appConfig.profiling); diff --git a/packages/core/ui/styling/style-scope.ts b/packages/core/ui/styling/style-scope.ts index e88a3141f..f1414217e 100644 --- a/packages/core/ui/styling/style-scope.ts +++ b/packages/core/ui/styling/style-scope.ts @@ -16,13 +16,25 @@ import { CssAnimationParser } from './css-animation-parser'; import { sanitizeModuleName } from '../../utils/common'; import { resolveModuleName } from '../../module-name-resolver'; import { cleanupImportantFlags } from './css-utils'; +import { cssTreeParse } from '../../css/css-tree-parser'; +import { CSS3Parser } from '../../css/CSS3Parser'; +import { CSSNativeScript } from '../../css/CSSNativeScript'; +import { parse as parseCss } from '../../css/lib/parse'; +// @ts-ignore apps resolve this at runtime with path alias in project bundlers +import appConfig from '~/package.json'; + +// if (!global.__dirname) { +// global.__dirname = typeof __dirname !== 'undefined' ? __dirname : import.meta.dirname; +// } +// const appPackagePath = path.join(global.__dirname, 'package.json'); +console.log('style-scope appConfig:', appConfig); let parser: 'rework' | 'nativescript' | 'css-tree' = 'css-tree'; try { console.log('style-scope here??'); // @ts-ignore - const appConfig = await import('~/package.json'); - console.log('style-scope appConfig:', appConfig); + // const appConfig = require('~/package.json'); + // console.log('style-scope appConfig:', appConfig); if (appConfig) { if (appConfig.cssParser === 'rework') { parser = 'rework'; @@ -238,17 +250,13 @@ class CSSSource { private async parseCSSAst() { if (this._source) { if (__CSS_PARSER__ === 'css-tree') { - const { cssTreeParse } = await import('../../css/css-tree-parser'); this._ast = cssTreeParse(this._source, this._file); } else if (__CSS_PARSER__ === 'nativescript') { - const { CSS3Parser } = await import('../../css/CSS3Parser'); - const { CSSNativeScript } = await import('../../css/CSSNativeScript'); const cssparser = new CSS3Parser(this._source); const stylesheet = cssparser.parseAStylesheet(); const cssNS = new CSSNativeScript(); this._ast = cssNS.parseStylesheet(stylesheet); } else if (__CSS_PARSER__ === 'rework') { - const { parse: parseCss } = await import('../../css'); this._ast = parseCss(this._source, { source: this._file }); } } @@ -558,6 +566,9 @@ export class CssState { } } + /** + * Checks whether style scope and CSS state selectors are in sync. + */ public isSelectorsLatestVersionApplied(): boolean { const view = this.viewRef.get(); if (!view) { @@ -923,6 +934,9 @@ export class StyleScope { return this.getSelectorsVersion(); } + /** + * Increase the application CSS selector version. + */ public _increaseApplicationCssSelectorVersion(): void { applicationCssSelectorVersion++; } diff --git a/packages/core/utils/native-helper.ios.ts b/packages/core/utils/native-helper.ios.ts index 59c79659d..7343f2242 100644 --- a/packages/core/utils/native-helper.ios.ts +++ b/packages/core/utils/native-helper.ios.ts @@ -92,7 +92,13 @@ export function dataSerialize(data: any, wrapPrimitives: boolean = false) { } function getCurrentAppPath(): string { - const currentDir = import.meta.dirname; + if (!global.__dirname) { + global.__dirname = typeof __dirname !== 'undefined' ? __dirname : import.meta.dirname; + } + console.log('getCurrentAppPath __dirname:', __dirname); + const currentDir = global.__dirname; + console.log('getCurrentAppPath global.__dirname:', global.__dirname); + console.log('getCurrentAppPath currentDir:', currentDir); const tnsModulesIndex = currentDir.indexOf('/tns_modules'); // Module not hosted in ~/tns_modules when bundled. Use current dir.