-
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: split
@pkgr/utils
into @pkgr/core
and @pkgr/browser
close #352
- Loading branch information
Showing
15 changed files
with
168 additions
and
84 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,7 +10,7 @@ | |
"workspaces": [ | ||
"packages/**" | ||
], | ||
"packageManager": "[email protected].19", | ||
"packageManager": "[email protected].21", | ||
"scripts": { | ||
"build": "run-s build:ts build:r", | ||
"build:r": "tsx packages/rollup/src/cli.ts -f cjs -d false", | ||
|
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
{ | ||
"name": "@pkgr/browser", | ||
"version": "0.0.0", | ||
"type": "module", | ||
"description": "Shared browser utils for `@pkgr` packages or any package else", | ||
"repository": "git+https://github.com/un-ts/pkgr.git", | ||
"homepage": "https://github.com/un-ts/pkgr/blob/master/packages/browser", | ||
"author": "JounQin (https://www.1stG.me) <[email protected]>", | ||
"funding": "https://opencollective.com/unts", | ||
"license": "MIT", | ||
"engines": { | ||
"node": "^12.20.0 || ^14.18.0 || >=16.0.0" | ||
}, | ||
"main": "./lib/index.cjs", | ||
"module": "./lib/index.js", | ||
"exports": { | ||
"types": "./lib/index.d.ts", | ||
"import": "./lib/index.js", | ||
"require": "./lib/index.cjs" | ||
}, | ||
"types": "./lib/index.d.ts", | ||
"files": [ | ||
"lib", | ||
"openChrome.applescript" | ||
], | ||
"dependencies": { | ||
"cross-spawn": "^7.0.3", | ||
"open": "^9.1.0", | ||
"picocolors": "^1.0.0", | ||
"tslib": "^2.6.1" | ||
}, | ||
"publishConfig": { | ||
"access": "public" | ||
}, | ||
"sideEffects": false | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
{ | ||
"extends": "@1stg/tsconfig/lib", | ||
"compilerOptions": { | ||
"composite": true, | ||
"outDir": "lib", | ||
"rootDir": "." | ||
}, | ||
"exclude": ["lib", "test"] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
{ | ||
"name": "@pkgr/core", | ||
"version": "0.0.0", | ||
"type": "module", | ||
"description": "Shared core module for `@pkgr` packages or any package else", | ||
"repository": "git+https://github.com/un-ts/pkgr.git", | ||
"homepage": "https://github.com/un-ts/pkgr/blob/master/packages/core", | ||
"author": "JounQin (https://www.1stG.me) <[email protected]>", | ||
"funding": "https://opencollective.com/unts", | ||
"license": "MIT", | ||
"engines": { | ||
"node": "^12.20.0 || ^14.18.0 || >=16.0.0" | ||
}, | ||
"main": "./lib/index.cjs", | ||
"module": "./lib/index.js", | ||
"exports": { | ||
"types": "./lib/index.d.ts", | ||
"import": "./lib/index.js", | ||
"require": "./lib/index.cjs" | ||
}, | ||
"types": "./lib/index.d.ts", | ||
"files": [ | ||
"lib" | ||
], | ||
"publishConfig": { | ||
"access": "public" | ||
}, | ||
"sideEffects": false | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import { createRequire } from 'node:module' | ||
|
||
export const CWD = process.cwd() | ||
|
||
export const cjsRequire = | ||
typeof require === 'undefined' ? createRequire(import.meta.url) : require | ||
|
||
// eslint-disable-next-line n/no-deprecated-api, sonar/deprecation | ||
export const EXTENSIONS = ['.ts', '.tsx', ...Object.keys(cjsRequire.extensions)] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
import fs from 'node:fs' | ||
import path from 'node:path' | ||
|
||
import { CWD, EXTENSIONS, cjsRequire } from './constants.js' | ||
|
||
export const tryPkg = (pkg: string) => { | ||
try { | ||
return cjsRequire.resolve(pkg) | ||
} catch {} | ||
} | ||
|
||
export const isPkgAvailable = (pkg: string) => !!tryPkg(pkg) | ||
|
||
export const tryFile = (filePath?: string[] | string, includeDir = false) => { | ||
if (typeof filePath === 'string') { | ||
return fs.existsSync(filePath) && | ||
(includeDir || fs.statSync(filePath).isFile()) | ||
? filePath | ||
: '' | ||
} | ||
|
||
for (const file of filePath ?? []) { | ||
if (tryFile(file, includeDir)) { | ||
return file | ||
} | ||
} | ||
|
||
return '' | ||
} | ||
|
||
export const tryExtensions = (filepath: string, extensions = EXTENSIONS) => { | ||
const ext = [...extensions, ''].find(ext => tryFile(filepath + ext)) | ||
return ext == null ? '' : filepath + ext | ||
} | ||
|
||
export const findUp = (searchEntry: string, searchFile = 'package.json') => { | ||
console.assert(path.isAbsolute(searchEntry)) | ||
|
||
if ( | ||
!tryFile(searchEntry, true) || | ||
(searchEntry !== CWD && !searchEntry.startsWith(CWD + path.sep)) | ||
) { | ||
return '' | ||
} | ||
|
||
searchEntry = path.resolve( | ||
fs.statSync(searchEntry).isDirectory() | ||
? searchEntry | ||
: path.resolve(searchEntry, '..'), | ||
) | ||
|
||
do { | ||
const searched = tryFile(path.resolve(searchEntry, searchFile)) | ||
if (searched) { | ||
return searched | ||
} | ||
searchEntry = path.resolve(searchEntry, '..') | ||
} while (searchEntry === CWD || searchEntry.startsWith(CWD + path.sep)) | ||
|
||
return '' | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
export * from './constants.js' | ||
export * from './helpers.js' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
{ | ||
"extends": "@1stg/tsconfig/lib", | ||
"compilerOptions": { | ||
"composite": true, | ||
"outDir": "lib", | ||
"rootDir": "src" | ||
}, | ||
"exclude": ["lib", "test"] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
export * from './browser.js' | ||
export * from './constants.js' | ||
export * from './helpers.js' | ||
export * from './monorepo.js' | ||
export * from '@pkgr/core' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters