Skip to content

Commit f349cbf

Browse files
committed
Migrate from deprecated --loader to modern --import flag
Update ESM loader registration to use the modern register() API with --import flag instead of the deprecated --loader flag. Align with socket-sdk-js naming convention: - Use scripts/register-loader.mjs (not in utils/) - Register scripts/utils/alias-loader.mjs via register() API - Update load.cjs to use --import flag This eliminates the ExperimentalWarning about --loader deprecation.
1 parent e8457be commit f349cbf

File tree

3 files changed

+9
-19
lines changed

3 files changed

+9
-19
lines changed

scripts/load.cjs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,10 @@ if (require.main === module) {
2929
const scriptPath = path.join(__dirname, scriptFile)
3030

3131
// Run the script with the alias loader.
32-
// Convert loader path to file:// URL for cross-platform ESM loader support (Windows requires file:// URLs)
33-
const loaderPath = path.join(__dirname, 'utils', 'alias-loader.mjs')
32+
// Convert register path to file:// URL for cross-platform ESM loader support (Windows requires file:// URLs)
33+
const registerPath = path.join(__dirname, 'register-loader.mjs')
3434
const args = [
35-
`--loader=${pathToFileURL(loaderPath).href}`,
35+
`--import=${pathToFileURL(registerPath).href}`,
3636
scriptPath,
3737
...flags,
3838
]

scripts/register-loader.mjs

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,15 @@
11
/**
2-
* @fileoverview Register module loader for aliasing @socketsecurity/lib to local build.
3-
* This should be imported at the very top of any script that needs local registry access.
2+
* @fileoverview Register alias loader for local Socket packages.
3+
* This module uses the modern register() API to load the alias-loader.
44
*/
55

6-
import { existsSync } from 'node:fs'
76
// eslint-disable-next-line n/no-unsupported-features/node-builtins -- Required for loader registration
87
import { register } from 'node:module'
98
import path from 'node:path'
109
import { fileURLToPath, pathToFileURL } from 'node:url'
1110

1211
const __dirname = path.dirname(fileURLToPath(import.meta.url))
13-
const rootPath = path.resolve(__dirname, '..')
14-
const registryPath = path.join(
15-
rootPath,
16-
'..',
17-
'socket-registry',
18-
'registry',
19-
'dist',
20-
)
12+
const loaderPath = path.join(__dirname, 'utils', 'alias-loader.mjs')
2113

22-
if (existsSync(registryPath)) {
23-
const loaderPath = path.join(__dirname, 'loader.mjs')
24-
register(pathToFileURL(loaderPath).href, import.meta.url)
25-
}
14+
// Register the alias loader using the modern API
15+
register(pathToFileURL(loaderPath).href, import.meta.url)

scripts/utils/alias-loader.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
* This file should be copied or imported from socket-registry to other repos.
66
*
77
* Usage:
8-
* node --loader=./scripts/utils/alias-loader.mjs script.mjs
8+
* node --import=./scripts/register-loader.mjs script.mjs
99
*/
1010

1111
import { existsSync } from 'node:fs'

0 commit comments

Comments
 (0)