@outputai/core 0.1.7-dev.0 → 0.1.7-dev.1a80bf4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@outputai/core",
3
- "version": "0.1.7-dev.0",
3
+ "version": "0.1.7-dev.1a80bf4.0",
4
4
  "description": "The core module of the output framework",
5
5
  "type": "module",
6
6
  "exports": {
@@ -1,5 +1,5 @@
1
1
  import { dirname, join } from 'node:path';
2
- import { existsSync, mkdirSync, writeFileSync } from 'node:fs';
2
+ import { existsSync, mkdirSync, readFileSync, writeFileSync } from 'node:fs';
3
3
  import { EOL } from 'node:os';
4
4
  import { fileURLToPath } from 'url';
5
5
  import { getTraceDestinations, sendHttpRequest } from '#internal_activities';
@@ -114,20 +114,39 @@ export async function loadWorkflows( rootDir ) {
114
114
  return workflows;
115
115
  };
116
116
 
117
+ const isPackageSpecifier = specifier => !specifier.startsWith( '.' ) && !specifier.startsWith( '/' );
118
+
119
+ const readPackageJson = pkgPath => JSON.parse( readFileSync( pkgPath, 'utf8' ) );
120
+
121
+ const resolveEsmEntry = pkg => pkg.exports?.['.']?.import ?? pkg.exports?.['.']?.default ?? pkg.main ?? 'index.js';
122
+
123
+ const resolvePackagePath = ( specifier, rootDir ) => {
124
+ const pkgJsonPath = join( rootDir, 'node_modules', specifier, 'package.json' );
125
+ if ( !existsSync( pkgJsonPath ) ) {
126
+ return null;
127
+ }
128
+ return join( rootDir, 'node_modules', specifier, resolveEsmEntry( readPackageJson( pkgJsonPath ) ) );
129
+ };
130
+
117
131
  /**
118
132
  * Loads the hook files from package.json's output config section.
119
133
  *
120
134
  * @param {string} rootDir
121
135
  * @returns {void}
122
136
  */
137
+ const resolveHookFile = ( specifier, rootDir ) =>
138
+ isPackageSpecifier( specifier ) ?
139
+ resolvePackagePath( specifier, rootDir ) ?? join( rootDir, specifier ) :
140
+ join( rootDir, specifier );
141
+
123
142
  export async function loadHooks( rootDir ) {
124
143
  const packageFile = join( rootDir, 'package.json' );
125
144
  if ( existsSync( packageFile ) ) {
126
145
  const pkg = await import( packageFile, { with: { type: 'json' } } );
127
- for ( const path of pkg.default.output?.hookFiles ?? [] ) {
128
- const hookFile = join( rootDir, path );
146
+ for ( const specifier of pkg.default.output?.hookFiles ?? [] ) {
147
+ const hookFile = resolveHookFile( specifier, rootDir );
129
148
  await import( hookFile );
130
- log.info( 'Hook file loaded', { path } );
149
+ log.info( 'Hook file loaded', { specifier } );
131
150
  }
132
151
  }
133
152
  };