Skip to content

Commit fad3196

Browse files
committed
Tweak exports and formats
1 parent d6e7f89 commit fad3196

10 files changed

+174
-66
lines changed

eslint.config.js renamed to eslint.config.mjs

Lines changed: 22 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,28 @@
1-
'use strict'
1+
import { createRequire } from 'node:module'
2+
import path from 'node:path'
3+
import url from 'node:url'
24

3-
const path = require('node:path')
4-
5-
const {
5+
import {
66
convertIgnorePatternToMinimatch,
77
includeIgnoreFile
8-
} = require('@eslint/compat')
9-
const jsPlugin = require('@eslint/js')
10-
const tsParser = require('@typescript-eslint/parser')
11-
const { createOxcImportResolver } = require('eslint-import-resolver-oxc')
12-
const importXPlugin = require('eslint-plugin-import-x')
13-
const jsdocPlugin = require('eslint-plugin-jsdoc')
14-
const nodePlugin = require('eslint-plugin-n')
15-
const sortDestructureKeysPlugin = require('eslint-plugin-sort-destructure-keys')
16-
const unicornPlugin = require('eslint-plugin-unicorn')
17-
const globals = require('globals')
18-
const tsEslint = require('typescript-eslint')
8+
} from '@eslint/compat'
9+
import jsPlugin from '@eslint/js'
10+
import tsParser from '@typescript-eslint/parser'
11+
import { createOxcImportResolver } from 'eslint-import-resolver-oxc'
12+
import importXPlugin from 'eslint-plugin-import-x'
13+
import jsdocPlugin from 'eslint-plugin-jsdoc'
14+
import nodePlugin from 'eslint-plugin-n'
15+
import sortDestructureKeysPlugin from 'eslint-plugin-sort-destructure-keys'
16+
import unicornPlugin from 'eslint-plugin-unicorn'
17+
import globals from 'globals'
18+
import tsEslint from 'typescript-eslint'
19+
20+
import constants from '@socketsecurity/registry/lib/constants'
21+
22+
const __filename = url.fileURLToPath(import.meta.url)
23+
const __dirname = path.dirname(__filename)
24+
const require = createRequire(import.meta.url)
1925

20-
const constants = require('@socketsecurity/registry/lib/constants')
2126
const { BIOME_JSON, GITIGNORE, LATEST, TSCONFIG_JSON } = constants
2227

2328
const { flatConfigs: origImportXFlatConfigs } = importXPlugin
@@ -141,7 +146,7 @@ function getImportXFlatConfigs(isEsm) {
141146
const importFlatConfigsForScript = getImportXFlatConfigs(false)
142147
const importFlatConfigsForModule = getImportXFlatConfigs(true)
143148

144-
module.exports = [
149+
export default [
145150
includeIgnoreFile(gitignorePath),
146151
{
147152
name: 'Imported biome.json ignore patterns',

package.json

Lines changed: 32 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,38 @@
1313
"type": "git",
1414
"url": "git://github.com/SocketDev/socket-sdk-js.git"
1515
},
16-
"main": "./dist/index.js",
17-
"module": "./dist/esm/index.js",
18-
"types": "./dist/index.d.ts",
16+
"type": "module",
17+
"exports": {
18+
".": {
19+
"node": {
20+
"module-sync": {
21+
"types": "./dist/index.d.mts",
22+
"default": "./dist/index.js"
23+
},
24+
"default": {
25+
"types": "./dist/index.d.cts",
26+
"default": "./dist/index.cjs"
27+
}
28+
},
29+
"default": {
30+
"types": "./dist/index.d.mts",
31+
"default": "./dist/index.js"
32+
}
33+
},
34+
"./dist/index.cjs": {
35+
"types": "./dist/index.d.cts",
36+
"default": "./dist/index.cjs"
37+
},
38+
"./dist/index.d.cts": "./dist/index.d.cts",
39+
"./dist/index.d.mts": "./dist/index.d.mts",
40+
"./package.json": "./package.json"
41+
},
1942
"scripts": {
20-
"build": "npm run clean && run-p -c --aggregate-output build:*",
43+
"build": "npm run clean && run-p -c --aggregate-output build:* && run-p -c --aggregate-output build:clean:*",
2144
"build:cjs": "tsc",
2245
"build:esm": "tsc -p tsconfig.esm.json",
46+
"build:clean:cjs": "node scripts/rename-dist-cjs-files.mjs",
47+
"build:clean:esm": "node scripts/rename-dist-esm-files.mjs",
2348
"check": "run-p -c --aggregate-output check:*",
2449
"check:lint": "eslint --report-unused-disable-directives .",
2550
"check:lint:fix": "npm run check:lint -- --fix",
@@ -29,10 +54,11 @@
2954
"coverage:type": "type-coverage --detail",
3055
"ci-test": "run-s build test:*",
3156
"clean": "run-p clean:*",
57+
"clean:dist": "del-cli 'dist'",
3258
"clean:declarations": "del-cli '*.d.ts' '!api*.d.ts'",
3359
"fix": "run-s lint:fix check:lint:fix",
34-
"generate-sdk:0-prettify": "node scripts/prettify-base-json.js",
35-
"generate-sdk:1-generate": "node scripts/generate-types.js > types/api.d.ts",
60+
"generate-sdk:0-prettify": "node scripts/prettify-base-json.mjs",
61+
"generate-sdk:1-generate": "node scripts/generate-types.mjs > types/api.d.ts",
3662
"generate-sdk": "run-s generate-sdk:*",
3763
"knip:dependencies": "knip --dependencies",
3864
"knip:exports": "knip --include exports,duplicates",

scripts/generate-types.js

Lines changed: 0 additions & 21 deletions
This file was deleted.

scripts/generate-types.mjs

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import path from 'node:path'
2+
import url from 'node:url'
3+
4+
import openapiTS from 'openapi-typescript'
5+
6+
const __filename = url.fileURLToPath(import.meta.url)
7+
const __dirname = path.dirname(__filename)
8+
9+
const rootPath = path.join(__dirname, '..')
10+
const openApiJsonPath = path.join(rootPath, 'openapi.json')
11+
12+
void (async () => {
13+
try {
14+
const output = await openapiTS(openApiJsonPath, {
15+
transform(schemaObject) {
16+
if ('format' in schemaObject && schemaObject.format === 'binary') {
17+
return 'never'
18+
}
19+
}
20+
})
21+
console.log(output)
22+
} catch (e) {
23+
process.exitCode = 1
24+
console.error('Failed with error:', e)
25+
}
26+
})()

scripts/prettify-base-json.js

Lines changed: 0 additions & 20 deletions
This file was deleted.

scripts/prettify-base-json.mjs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import fs from 'node:fs/promises'
2+
import path from 'node:path'
3+
import url from 'node:url'
4+
5+
const __filename = url.fileURLToPath(import.meta.url)
6+
const __dirname = path.dirname(__filename)
7+
8+
const rootPath = path.join(__dirname, '..')
9+
const openApiJsonPath = path.join(rootPath, 'openapi.json')
10+
11+
void (async () => {
12+
try {
13+
const openApiData = await fs.readFile(openApiJsonPath, 'utf8')
14+
await fs.writeFile(
15+
openApiJsonPath,
16+
JSON.stringify(JSON.parse(openApiData), null, 2)
17+
)
18+
} catch (e) {
19+
process.exitCode = 1
20+
console.error('Failed with error:', e.stack)
21+
}
22+
})()

scripts/rename-dist-cjs-files.mjs

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
import fs from 'node:fs/promises'
2+
import path from 'node:path'
3+
import url from 'node:url'
4+
5+
const __filename = url.fileURLToPath(import.meta.url)
6+
const __dirname = path.dirname(__filename)
7+
8+
const rootPath = path.join(__dirname, '..')
9+
const distPath = path.join(rootPath, 'dist')
10+
const distCjsPath = path.join(distPath, 'cjs')
11+
12+
void (async () => {
13+
await Promise.all([
14+
fs.rename(
15+
path.join(distCjsPath, 'index.d.ts'),
16+
path.join(distPath, 'index.d.cts')
17+
),
18+
fs.rename(
19+
path.join(distCjsPath, 'index.d.ts.map'),
20+
path.join(distPath, 'index.d.cts.map')
21+
),
22+
fs.rename(
23+
path.join(distCjsPath, 'index.js'),
24+
path.join(distPath, 'index.cjs')
25+
),
26+
fs.rename(
27+
path.join(distCjsPath, 'index.js.map'),
28+
path.join(distPath, 'index.cjs.map')
29+
)
30+
])
31+
await Promise.all([
32+
fs.rm(distCjsPath, { recursive: true }),
33+
fs.rm(path.join(distPath, 'tsconfig.tsbuildinfo'))
34+
])
35+
})()

scripts/rename-dist-esm-files.mjs

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
import fs from 'node:fs/promises'
2+
import path from 'node:path'
3+
import url from 'node:url'
4+
5+
const __filename = url.fileURLToPath(import.meta.url)
6+
const __dirname = path.dirname(__filename)
7+
8+
const rootPath = path.join(__dirname, '..')
9+
const distPath = path.join(rootPath, 'dist')
10+
const distEsmPath = path.join(distPath, 'esm')
11+
12+
void (async () => {
13+
await Promise.all([
14+
fs.rename(
15+
path.join(distEsmPath, 'index.d.ts'),
16+
path.join(distPath, 'index.d.mts')
17+
),
18+
fs.rename(
19+
path.join(distEsmPath, 'index.d.ts.map'),
20+
path.join(distPath, 'index.d.mts.map')
21+
),
22+
fs.rename(
23+
path.join(distEsmPath, 'index.js'),
24+
path.join(distPath, 'index.js')
25+
),
26+
fs.rename(
27+
path.join(distEsmPath, 'index.js.map'),
28+
path.join(distPath, 'index.js.map')
29+
)
30+
])
31+
await Promise.all([
32+
fs.rm(distEsmPath, { recursive: true }),
33+
fs.rm(path.join(distPath, 'tsconfig.esm.tsbuildinfo'))
34+
])
35+
})()

src/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ export interface SocketSdkOptions {
3434
userAgent?: string | undefined
3535
}
3636

37-
const rootPath = path.join(__dirname, '../..')
37+
const rootPath = path.join(__dirname, '..')
3838
const rootPkgJsonPath = path.join(rootPath, 'package.json')
3939

4040
const defaultUserAgent = createUserAgentFromPkgJson(require(rootPkgJsonPath))

test/main.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import nock from 'nock'
22
import { afterEach, beforeEach, describe, expect, it } from 'vitest'
33

4-
import { SocketSdk } from '../dist/esm/index.js'
4+
import { SocketSdk } from '../dist/index.js'
55

66
process.on('unhandledRejection', cause => {
77
throw new Error('Unhandled rejection', { cause })

0 commit comments

Comments
 (0)