Skip to content
This repository has been archived by the owner on Jan 25, 2025. It is now read-only.

Commit

Permalink
1.2.4 (#167)
Browse files Browse the repository at this point in the history
  • Loading branch information
JensAstrup authored Apr 16, 2024
2 parents 4c57d6d + aa2f937 commit c69b0e9
Show file tree
Hide file tree
Showing 11 changed files with 329 additions and 89 deletions.
1 change: 1 addition & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
node_modules
lib
/dist/
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@
/lib/
/coverage/
docs/
/dist/
27 changes: 18 additions & 9 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,22 +1,30 @@
{
"name": "shortcut-api",
"version": "1.2.3",
"main": "lib/index.js",
"types": "lib/index.d.ts",
"version": "1.2.4",
"main": "dist/cjs/index.js",
"module": "dist/esm/index.js",
"types": "dist/esm/index.d.ts",
"files": [
"lib"
"dist"
],
"exports": {
".": {
"import": "./lib/index.js",
"require": "./lib/index.js"
}
"import": "./dist/esm/index.mjs",
"require": "./dist/cjs/index.cjs"
},
"./package.json": "./package.json"
},
"type": "module",
"description": "An API Wrapper for Shortcut, using an object oriented approach to interact with the Shortcut API",
"scripts": {
"build": "rm -rf lib && tsc && tscpaths -p tsconfig.json -s ./src -o ./lib && npm run reformatImports",
"reformatImports": "node ./scripts/reformat-imports.js",
"build": "rm -rf dist && npm run compile:esm && npm run compile:cjs && npm run replace-paths && npm run rename:esm && npm run rename:cjs && npm run reformat-imports:esm && npm run reformat-imports:cjs",
"compile:esm": "tsc -p tsconfig.esm.json",
"compile:cjs": "tsc -p tsconfig.cjs.json",
"rename:esm": "renamer --path-element ext --find js --replace mjs './dist/esm/**/*.js'",
"rename:cjs": "renamer --path-element ext --find js --replace cjs './dist/cjs/**/*.js'",
"replace-paths": "tscpaths -p tsconfig.esm.json -s ./src -o ./dist/esm && tscpaths -p tsconfig.cjs.json -s ./src -o ./dist/cjs",
"reformat-imports:esm": "node scripts/reformat-esm-imports.js",
"reformat-imports:cjs": "node scripts/reformat-cjs-imports.js",
"prepublishOnly": "npm run build",
"test": "jest",
"docs": "npx typedoc",
Expand All @@ -41,6 +49,7 @@
"eslint-plugin-import": "^2.29.1",
"eslint-plugin-perfectionist": "^2.7.0",
"jest": "^29.7.0",
"renamer": "^5.0.0",
"ts-jest": "^29.1.2",
"ts-node": "^10.9.2",
"tsconfig-paths": "^4.2.0",
Expand Down
40 changes: 40 additions & 0 deletions scripts/reformat-cjs-imports.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import fs from 'fs'
import path from 'path'
import {fileURLToPath} from 'url'


const __filename = fileURLToPath(import.meta.url)
const dirname = path.dirname(__filename)


function appendJsExtension(file) {
const content = fs.readFileSync(file, 'utf8')
const updatedContent = content.replace(/require\(['"]([^'"]+)['"]\)/g, (match, p1) => {
// Append .js to relative paths if missing and not already ending with .js or .json
if (p1.startsWith('.') && !p1.endsWith('.js') && !p1.endsWith('.json')) {
return `require('${p1}.cjs')`
}
return match
})

fs.writeFileSync(file, updatedContent, 'utf8')
}

function processDirectory(directory) {
fs.readdirSync(directory, {withFileTypes: true}).forEach(dirent => {
const fullPath = path.join(directory, dirent.name)
if (dirent.isDirectory()) {
processDirectory(fullPath)
}
else if (dirent.isFile() && dirent.name.endsWith('.cjs')) {
appendJsExtension(fullPath)
}
})
}

// The directory containing your compiled JavaScript files.
// Adjust this path as necessary.
const compiledDir = path.join(dirname, '../dist/cjs')
processDirectory(compiledDir)

console.log('Import paths have been fixed for CJS modules.')
41 changes: 41 additions & 0 deletions scripts/reformat-esm-imports.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import fs from 'fs'
import path from 'path'
import {fileURLToPath} from 'url'


const __filename = fileURLToPath(import.meta.url)
const dirname = path.dirname(__filename)


function addJsExtension(file) {
const content = fs.readFileSync(file, 'utf8')
const updatedContent = content.replace(/from\s+['"]([^'"]+)['"]/g, (match, p1) => {
// Don't modify node_modules imports or absolute paths or URLs
if (p1.startsWith('.') && !p1.endsWith('.js') && !p1.endsWith('.json')) {
return `from '${p1}.mjs'`
}
return match
})

fs.writeFileSync(file, updatedContent, 'utf8')
}

function processDirectory(directory) {
fs.readdirSync(directory, {withFileTypes: true}).forEach(dirent => {
const fullPath = path.join(directory, dirent.name)
if (dirent.isDirectory()) {
processDirectory(fullPath)
}
else if (dirent.isFile() && dirent.name.endsWith('.mjs')) {
addJsExtension(fullPath)
}
})
}

// The directory containing your compiled JavaScript files.
// Adjust this path as necessary.
const compiledDir = path.join(dirname, '../dist/esm')

processDirectory(compiledDir)

console.log('Import paths have been fixed.')
39 changes: 0 additions & 39 deletions scripts/reformat-imports.js

This file was deleted.

41 changes: 41 additions & 0 deletions tsconfig.base.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
{
"compilerOptions": {
"target": "es2022",
"lib": [
"ES2022"
],
"strictNullChecks": true,
"alwaysStrict": true,
"moduleResolution": "node",
"baseUrl": "./",
"declaration": true,
"esModuleInterop": true,
"forceConsistentCasingInFileNames": true,
"strict": true,
"skipLibCheck": true,
"paths": {
"@sx/*": [
"./src/*"
]
},
"experimentalDecorators": true,
"emitDecoratorMetadata": true,
"allowSyntheticDefaultImports": true,
"resolveJsonModule": true,
"strictPropertyInitialization": false
},
"ts-node": {
"esm": true
},
"include": [
"./src/**/*.ts"
],
"exclude": [
"node_modules",
"dist"
],
"plugins": [
"@typescript-eslint",
"import"
]
}
8 changes: 8 additions & 0 deletions tsconfig.cjs.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"extends": "./tsconfig.base.json",
"compilerOptions": {
"module": "CommonJS",
"outDir": "./dist/cjs"
},
"include": ["src/**/*"]
}
8 changes: 8 additions & 0 deletions tsconfig.esm.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"extends": "./tsconfig.base.json",
"compilerOptions": {
"module": "ESNext",
"outDir": "./dist/esm"
},
"include": ["src/**/*"]
}
43 changes: 4 additions & 39 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,43 +1,8 @@
{
"extends": "./tsconfig.esm.json",
"compilerOptions": {
"target": "es2022",
"lib": [
"ES2022"
],
"strictNullChecks": true,
"alwaysStrict": true,
"module": "commonjs",
"moduleResolution": "node",
"baseUrl": "./",
"declaration": true,
"outDir": "./lib",
"esModuleInterop": true,
"forceConsistentCasingInFileNames": true,
"strict": true,
"skipLibCheck": true,
"paths": {
"@sx/*": [
"./src/*"
]
},
"experimentalDecorators": true,
"emitDecoratorMetadata": true,
"allowSyntheticDefaultImports": true,
"resolveJsonModule": true,
"strictPropertyInitialization": false
"module": "ESNext",
"outDir": "./dist/esm"
},
"ts-node": {
"esm": true
},
"include": [
"./src/**/*.ts"
],
"exclude": [
"node_modules",
"lib"
],
"plugins": [
"@typescript-eslint",
"import"
]
"include": ["src/**/*"]
}
Loading

0 comments on commit c69b0e9

Please sign in to comment.