@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 +1 -1
- package/src/worker/loader.js +23 -4
package/package.json
CHANGED
package/src/worker/loader.js
CHANGED
|
@@ -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
|
|
128
|
-
const hookFile =
|
|
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', {
|
|
149
|
+
log.info( 'Hook file loaded', { specifier } );
|
|
131
150
|
}
|
|
132
151
|
}
|
|
133
152
|
};
|