-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(bananass-utils): create
bananass-utils
package (#39)
This pull request includes several changes to the `bananass-utils` package, focusing on module restructuring, configuration updates, and the addition of tests. The most important changes include the creation of a new `package.json` for the package, renaming and refactoring of utility files, and adding a test file for the `getRootDir` function. ### Module restructuring: * [`packages/bananass-utils/src/fs/getRootDir.js`](diffhunk://#diff-2d73861b7a48a161b6c7da8bc708a835f7ed4980c32798208f340991861d2bd6L6-R18): Renamed from `packages/bananass/src/utils/fs/getRootDir.js` and refactored to use ES module syntax. * [`packages/bananass-utils/src/fs/index.js`](diffhunk://#diff-d309721639755fea30f691711d2b84d859f75dc4f3e0cc4bebdf786c00570d5fR5-R17): Renamed from `packages/bananass/src/utils/fs/index.js` and updated to use ES module syntax. * [`packages/bananass-utils/src/index.js`](diffhunk://#diff-63cf995490728ee71e1a41cc3d6e933dbb9598f4d8a66dd0a73545c5cea7c0eeR1-R18): Created as the entry file for the `bananass-utils` package. ### Configuration updates: * [`packages/bananass-utils/babel.config.cjs`](diffhunk://#diff-32a42043d854a596d61233b88b1a487f3573598afbe3c55b57cf78ae3e01281cR1-R3): Added to extend the base Babel configuration. * [`packages/bananass-utils/package.json`](diffhunk://#diff-d163ef114bef61820f7f4b4d32b3deb5f15dfc2b5375c030716132c1b4c31c88R1-R48): Created to define the package metadata and scripts. * [`packages/bananass-utils/tsconfig.json`](diffhunk://#diff-a53266bd7f210cfde5d4b24b78800f41fdacbd504fea3296501e89690aacd9a5R1-R10): Added to configure TypeScript compilation. ### Addition of tests: * [`packages/bananass-utils/src/fs/getRootDir.test.js`](diffhunk://#diff-c0482ef0af3b1ae543cd63149daad3275a533bcf07ee593e896d1d88e94504e3R1-R78): Created to test the `getRootDir` function. ### Code updates: * [`packages/bananass/src/commands/bananass-build/webpack.js`](diffhunk://#diff-0ce95c8c9e2a9153c60042f1f9db2f62324e019f7980eb2e8ee8a5001fd6e34bR12-R13): Updated to import `getRootDir` from `bananass-utils/fs` instead of the local path. [[1]](diffhunk://#diff-0ce95c8c9e2a9153c60042f1f9db2f62324e019f7980eb2e8ee8a5001fd6e34bR12-R13) [[2]](diffhunk://#diff-0ce95c8c9e2a9153c60042f1f9db2f62324e019f7980eb2e8ee8a5001fd6e34bL26)
- Loading branch information
1 parent
9a485c4
commit 585ee31
Showing
9 changed files
with
192 additions
and
21 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,3 @@ | ||
module.exports = { | ||
extends: '../../babel.config.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,48 @@ | ||
{ | ||
"name": "bananass-utils", | ||
"version": "0.0.0", | ||
"type": "module", | ||
"description": "Utilities except console for Bananass Framework.🍌", | ||
"exports": { | ||
".": { | ||
"types": "./build/index.d.ts", | ||
"default": "./build/index.js" | ||
}, | ||
"./fs": { | ||
"types": "./build/fs/index.d.ts", | ||
"default": "./build/fs/index.js" | ||
}, | ||
"./package.json": "./package.json" | ||
}, | ||
"files": [ | ||
"build", | ||
"LICENSE.md", | ||
"README.md" | ||
], | ||
"keywords": [ | ||
"bananass", | ||
"baekjoon", | ||
"framework", | ||
"javascript", | ||
"utils" | ||
], | ||
"author": "루밀LuMir <[email protected]> (https://github.com/lumirlumir)", | ||
"license": "MIT", | ||
"homepage": "https://github.com/lumirlumir/npm-bananass", | ||
"repository": { | ||
"type": "github", | ||
"url": "git+https://github.com/lumirlumir/npm-bananass.git", | ||
"directory": "packages/bananass-utils" | ||
}, | ||
"bugs": { | ||
"url": "https://github.com/lumirlumir/npm-bananass/issues" | ||
}, | ||
"engines": { | ||
"node": ">=20.18.0" | ||
}, | ||
"scripts": { | ||
"prepublishOnly": "npm run build", | ||
"build": "npx babel src -d build && npx tsc && cp ../../LICENSE.md ../../README.md .", | ||
"test": "node --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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
/** | ||
* @fileoverview Test for `getRootDir.js`. | ||
*/ | ||
|
||
/* eslint-disable import/extensions */ // TODO: Remove this line after developing `eslint-config-bananass` package. | ||
|
||
// -------------------------------------------------------------------------------- | ||
// Import | ||
// -------------------------------------------------------------------------------- | ||
|
||
import { strictEqual, throws } from 'node:assert'; | ||
import { describe, it, mock, afterEach } from 'node:test'; | ||
import { resolve } from 'node:path'; | ||
import cp from 'node:child_process'; | ||
import fs from 'node:fs'; | ||
|
||
import getRootDir from './getRootDir.js'; | ||
|
||
// -------------------------------------------------------------------------------- | ||
// Test | ||
// -------------------------------------------------------------------------------- | ||
|
||
afterEach(() => { | ||
mock.reset(); | ||
}); | ||
|
||
describe('getRootDir.js', () => { | ||
it('should return `process.cwd()` when `package.json` exists in current directory', () => { | ||
const MOCK_CWD = resolve('my-folder', 'cwd'); | ||
const MOCK_VALID_PATHS = [MOCK_CWD, resolve(MOCK_CWD, 'package.json')]; | ||
|
||
mock.method(process, 'cwd', () => MOCK_CWD); | ||
mock.method(fs, 'existsSync', path => MOCK_VALID_PATHS.includes(path)); | ||
|
||
strictEqual(getRootDir(), MOCK_CWD); | ||
}); | ||
|
||
it('should throw error when git command fails', () => { | ||
const MOCK_CWD = resolve('my-folder', 'cwd'); | ||
const MOCK_VALID_PATHS = [MOCK_CWD, resolve(MOCK_CWD, '..', 'package.json')]; | ||
|
||
mock.method(process, 'cwd', () => MOCK_CWD); | ||
mock.method(fs, 'existsSync', path => MOCK_VALID_PATHS.includes(path)); | ||
mock.method(cp, 'execSync', () => { | ||
throw new Error('Throw error'); | ||
}); | ||
|
||
throws(() => getRootDir(), { name: 'Error', message: /Git command failed/ }); | ||
}); | ||
|
||
it('should return git root when `package.json` exists only in git root', () => { | ||
const MOCK_CWD = resolve('my-folder', 'cwd'); | ||
const MOCK_GIT_ROOT = resolve(MOCK_CWD, '..'); | ||
const MOCK_VALID_PATHS = [ | ||
MOCK_CWD, | ||
MOCK_GIT_ROOT, | ||
resolve(MOCK_GIT_ROOT, 'package.json'), | ||
]; | ||
|
||
mock.method(process, 'cwd', () => MOCK_CWD); | ||
mock.method(fs, 'existsSync', path => MOCK_VALID_PATHS.includes(path)); | ||
mock.method(cp, 'execSync', () => MOCK_GIT_ROOT); | ||
|
||
strictEqual(getRootDir(), MOCK_GIT_ROOT); | ||
}); | ||
|
||
it('should throw error when `package.json` not found anywhere', () => { | ||
const MOCK_CWD = resolve('my-folder', 'cwd'); | ||
const MOCK_GIT_ROOT = resolve(MOCK_CWD, '..'); | ||
const MOCK_VALID_PATHS = [MOCK_CWD, MOCK_GIT_ROOT]; | ||
|
||
mock.method(process, 'cwd', () => MOCK_CWD); | ||
mock.method(fs, 'existsSync', path => MOCK_VALID_PATHS.includes(path)); | ||
mock.method(cp, 'execSync', () => MOCK_GIT_ROOT); | ||
|
||
throws(() => getRootDir(), { name: 'Error', message: /Cannot find root directory/ }); | ||
}); | ||
}); |
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 |
---|---|---|
@@ -0,0 +1,18 @@ | ||
/** | ||
* @fileoverview Entry file for the `bananass-utils` package. | ||
* @module bananass-utils | ||
*/ | ||
|
||
/* eslint-disable import/extensions, import/prefer-default-export */ // TODO: Remove this line after developing `eslint-config-bananass` package. | ||
|
||
// -------------------------------------------------------------------------------- | ||
// Import | ||
// -------------------------------------------------------------------------------- | ||
|
||
import fs from './fs/index.js'; | ||
|
||
// -------------------------------------------------------------------------------- | ||
// Export | ||
// -------------------------------------------------------------------------------- | ||
|
||
export { fs }; |
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,10 @@ | ||
{ | ||
"compilerOptions": { | ||
"allowJs": true, | ||
"declaration": true, | ||
"emitDeclarationOnly": true, | ||
"outDir": "build" | ||
}, | ||
"include": ["src/**/*.js"], | ||
"exclude": ["src/**/*.test.js", "src/**/*.spec.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