pax_global_header00006660000000000000000000000064151566635210014524gustar00rootroot0000000000000052 comment=1f30d7aba606c8d700ad1ae7e5fe0bd05d47328d jaywcjlove-auto-config-loader-849af3a/000077500000000000000000000000001515666352100177775ustar00rootroot00000000000000jaywcjlove-auto-config-loader-849af3a/.github/000077500000000000000000000000001515666352100213375ustar00rootroot00000000000000jaywcjlove-auto-config-loader-849af3a/.github/FUNDING.yml000066400000000000000000000001701515666352100231520ustar00rootroot00000000000000github: [jaywcjlove] # ko_fi: jaywcjlove # buy_me_a_coffee: jaywcjlove # custom: ["https://wangchujiang.com/#/sponsor"] jaywcjlove-auto-config-loader-849af3a/.github/workflows/000077500000000000000000000000001515666352100233745ustar00rootroot00000000000000jaywcjlove-auto-config-loader-849af3a/.github/workflows/main.yml000066400000000000000000000104041515666352100250420ustar00rootroot00000000000000name: Node.js CI on: push jobs: build: runs-on: ubuntu-latest permissions: contents: write id-token: write steps: - uses: actions/checkout@v6 - uses: actions/setup-node@v6 with: node-version: 24 registry-url: 'https://registry.npmjs.org' - run: npm install - run: npm run build working-directory: core - run: npm install idoc@1 -g - name: Create idoc config. working-directory: core run: | cat > idoc.yml << EOF site: "Auto Config Loader {{version}}" menus: Home: index.html Apps: url: https://wangchujiang.com/#/app target: __blank Sponsor: url: https://wangchujiang.com/#/sponsor target: __blank footer: | Contact • Projects • Sponsor • More Apps

Generated by idoc v{{idocVersion}} EOF - run: idoc working-directory: core - run: npm run coverage && cp -rp coverage/lcov-report ./dist working-directory: core - name: Generate Contributors Images uses: jaywcjlove/github-action-contributors@main with: filter-author: (renovate\[bot\]|renovate-bot|dependabot\[bot\]) output: core/dist/CONTRIBUTORS.svg avatarSize: 42 - name: Create Coverage Badges uses: jaywcjlove/coverage-badges-cli@main with: source: core/coverage/coverage-summary.json output: core/dist/badges.svg - name: Is a tag created auto? id: create_tag uses: jaywcjlove/create-tag-action@main with: token: ${{ secrets.GITHUB_TOKEN }} package-path: core/package.json - name: Deploy Website uses: peaceiris/actions-gh-pages@v4 with: user_name: 'github-actions[bot]' user_email: 'github-actions[bot]@users.noreply.github.com' commit_message: ${{steps.create_tag.outputs.version}} ${{ github.event.head_commit.message }} github_token: ${{ secrets.GITHUB_TOKEN }} publish_dir: ./core/dist - name: Generate Changelog id: changelog uses: jaywcjlove/changelog-generator@main if: steps.create_tag.outputs.successful with: token: ${{ secrets.GITHUB_TOKEN }} head-ref: ${{ steps.create_tag.outputs.version }} filter-author: (小弟调调™|Renovate Bot|renovate-bot) filter: '[R|r]elease[d]\s+[v|V]\d(\.\d+){0,2}' - name: package.json info uses: jaywcjlove/github-action-package@main with: path: core/package.json unset: scripts - run: NODE_AUTH_TOKEN="" npm publish --access public --provenance continue-on-error: true working-directory: core - name: Create Release uses: ncipollo/release-action@v1 if: steps.create_tag.outputs.successful with: allowUpdates: true token: ${{ secrets.GITHUB_TOKEN }} name: ${{ steps.create_tag.outputs.version }} tag: ${{ steps.create_tag.outputs.version }} body: | [![Buy me a coffee](https://img.shields.io/badge/Buy%20me%20a%20coffee-048754?logo=buymeacoffee)](https://jaywcjlove.github.io/#/sponsor) [![](https://img.shields.io/badge/Open%20in-unpkg-blue)](https://uiwjs.github.io/npm-unpkg/#/pkg/auto-config-loader@${{steps.create_tag.outputs.versionNumber}}/file/README.md) Documentation ${{ steps.changelog.outputs.tag }}: https://raw.githack.com/jaywcjlove/auto-config-loader/${{ steps.changelog.outputs.gh-pages-short-hash }}/index.html ```bash npm i auto-config-loader@${{steps.create_tag.outputs.versionNumber}} ``` ${{ steps.changelog.outputs.compareurl }} ${{ steps.changelog.outputs.changelog }}jaywcjlove-auto-config-loader-849af3a/.github/workflows/test.yml000066400000000000000000000022101515666352100250710ustar00rootroot00000000000000name: Node.js CI on: # 手动触发 workflow_dispatch: jobs: Ubuntu: name: Ubuntu Node.js ${{ matrix.node-version }} # Containers must run in Linux based operating systems runs-on: ubuntu-latest strategy: fail-fast: false matrix: node-version: - 24 - 20 steps: - uses: actions/checkout@v6 - uses: actions/setup-node@v6 with: node-version: ${{ matrix.node-version }} - run: npm install - run: npm run build working-directory: core - run: npm run coverage working-directory: core Windows: name: Windows Node.js ${{ matrix.node-version }} # Containers must run in Linux based operating systems runs-on: windows-latest strategy: fail-fast: false matrix: node-version: - 24 - 20 steps: - uses: actions/checkout@v6 - uses: actions/setup-node@v6 with: node-version: ${{ matrix.node-version }} - run: npm install - run: npm run build working-directory: core - run: npm run coverage working-directory: corejaywcjlove-auto-config-loader-849af3a/.gitignore000066400000000000000000000003331515666352100217660ustar00rootroot00000000000000coverage dist build lib node_modules npm-debug.log* lerna-debug.log yarn-error.log package-lock.json .DS_Store .cache .vscode .idea .env *.mpassword *.bak *.tem *.temp #.swp *.*~ ~*.* # IDEA *.iml *.ipr *.iws .idea/jaywcjlove-auto-config-loader-849af3a/.husky/000077500000000000000000000000001515666352100212205ustar00rootroot00000000000000jaywcjlove-auto-config-loader-849af3a/.husky/pre-commit000077500000000000000000000000341515666352100232170ustar00rootroot00000000000000npx --no-install lint-stagedjaywcjlove-auto-config-loader-849af3a/.prettierignore000066400000000000000000000002161515666352100230410ustar00rootroot00000000000000**/*.md **/*.svg **/*.ejs **/*.html **/*.yml **/*.d.ts package.json node_modules dist build lib test package.json coverage dist build cjs esmjaywcjlove-auto-config-loader-849af3a/.prettierrc000066400000000000000000000004011515666352100221560ustar00rootroot00000000000000{ "singleQuote": true, "trailingComma": "all", "printWidth": 120, "overrides": [ { "files": ".prettierrc", "options": { "parser": "json" } }, { "files": ".lintstagedrc", "options": { "parser": "json" } } ] }jaywcjlove-auto-config-loader-849af3a/LICENSE000066400000000000000000000020551515666352100210060ustar00rootroot00000000000000MIT License Copyright (c) 2023 小弟调调 Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. jaywcjlove-auto-config-loader-849af3a/README.md000077700000000000000000000000001515666352100234602core/README.mdustar00rootroot00000000000000jaywcjlove-auto-config-loader-849af3a/config-example/000077500000000000000000000000001515666352100226755ustar00rootroot00000000000000jaywcjlove-auto-config-loader-849af3a/config-example/.autoconfrc000066400000000000000000000000201515666352100250310ustar00rootroot00000000000000{ "one": 123 }jaywcjlove-auto-config-loader-849af3a/config-example/autoconfrcjson/000077500000000000000000000000001515666352100257325ustar00rootroot00000000000000jaywcjlove-auto-config-loader-849af3a/config-example/autoconfrcjson/.autoconfrc.json000066400000000000000000000000321515666352100310410ustar00rootroot00000000000000{ "name": "auto-conf" } jaywcjlove-auto-config-loader-849af3a/config-example/config-dir-cjs/000077500000000000000000000000001515666352100254735ustar00rootroot00000000000000jaywcjlove-auto-config-loader-849af3a/config-example/config-dir-cjs/.config/000077500000000000000000000000001515666352100270165ustar00rootroot00000000000000jaywcjlove-auto-config-loader-849af3a/config-example/config-dir-cjs/.config/autoconfrc.cjs000066400000000000000000000000671515666352100316650ustar00rootroot00000000000000module.exports = { projectName: 'ext-config-cjs', }; jaywcjlove-auto-config-loader-849af3a/config-example/config-dir-ini/000077500000000000000000000000001515666352100254735ustar00rootroot00000000000000jaywcjlove-auto-config-loader-849af3a/config-example/config-dir-ini/.config/000077500000000000000000000000001515666352100270165ustar00rootroot00000000000000jaywcjlove-auto-config-loader-849af3a/config-example/config-dir-ini/.config/autoconfrc.ini000066400000000000000000000003471515666352100316660ustar00rootroot00000000000000; this comment is being ignored scope = global [database] user = dbuser password = dbpassword database = use_this_database [paths.default] datadir = /var/lib/data array[] = first value array[] = second value array[] = third valuejaywcjlove-auto-config-loader-849af3a/config-example/config-dir-js/000077500000000000000000000000001515666352100253305ustar00rootroot00000000000000jaywcjlove-auto-config-loader-849af3a/config-example/config-dir-js/.config/000077500000000000000000000000001515666352100266535ustar00rootroot00000000000000jaywcjlove-auto-config-loader-849af3a/config-example/config-dir-js/.config/autoconfrc.js000066400000000000000000000000611515666352100313510ustar00rootroot00000000000000export default { projectName: 'ext-config-js' }; jaywcjlove-auto-config-loader-849af3a/config-example/config-dir-json/000077500000000000000000000000001515666352100256655ustar00rootroot00000000000000jaywcjlove-auto-config-loader-849af3a/config-example/config-dir-json/.config/000077500000000000000000000000001515666352100272105ustar00rootroot00000000000000jaywcjlove-auto-config-loader-849af3a/config-example/config-dir-json/.config/autoconfrc.json000066400000000000000000000000211515666352100322370ustar00rootroot00000000000000{ "one": 123 } jaywcjlove-auto-config-loader-849af3a/config-example/config-dir-json5/000077500000000000000000000000001515666352100257525ustar00rootroot00000000000000jaywcjlove-auto-config-loader-849af3a/config-example/config-dir-json5/.config/000077500000000000000000000000001515666352100272755ustar00rootroot00000000000000jaywcjlove-auto-config-loader-849af3a/config-example/config-dir-json5/.config/autoconfrc.json000066400000000000000000000004651515666352100323400ustar00rootroot00000000000000{ // 注释 "projectName": "ext-json", "name": "my-app", // 允许使用十六进制和八进制数值 "hex": 0x1a, "octal": 0o755, // 允许使用 NaN、Infinity 和 -Infinity "max": Infinity, "min": -Infinity, "notANumber": NaN, // 允许使用尾随逗号 "react-dom": "^16.13.1" } jaywcjlove-auto-config-loader-849af3a/config-example/config-dir-jsonc/000077500000000000000000000000001515666352100260305ustar00rootroot00000000000000jaywcjlove-auto-config-loader-849af3a/config-example/config-dir-jsonc/.config/000077500000000000000000000000001515666352100273535ustar00rootroot00000000000000jaywcjlove-auto-config-loader-849af3a/config-example/config-dir-jsonc/.config/autoconfrc.jsonc000066400000000000000000000000541515666352100325530ustar00rootroot00000000000000{ // 注释 "projectName": "ext-jsonc" }jaywcjlove-auto-config-loader-849af3a/config-example/config-dir-mjs/000077500000000000000000000000001515666352100255055ustar00rootroot00000000000000jaywcjlove-auto-config-loader-849af3a/config-example/config-dir-mjs/.config/000077500000000000000000000000001515666352100270305ustar00rootroot00000000000000jaywcjlove-auto-config-loader-849af3a/config-example/config-dir-mjs/.config/autoconfrc.mjs000066400000000000000000000000611515666352100317030ustar00rootroot00000000000000export default { projectName: 'ext-config-mjs' };jaywcjlove-auto-config-loader-849af3a/config-example/config-dir-rc/000077500000000000000000000000001515666352100253205ustar00rootroot00000000000000jaywcjlove-auto-config-loader-849af3a/config-example/config-dir-rc/.config/000077500000000000000000000000001515666352100266435ustar00rootroot00000000000000jaywcjlove-auto-config-loader-849af3a/config-example/config-dir-rc/.config/autoconfrc000066400000000000000000000000201515666352100307210ustar00rootroot00000000000000{ "one": 123 }jaywcjlove-auto-config-loader-849af3a/config-example/config-dir-toml/000077500000000000000000000000001515666352100256675ustar00rootroot00000000000000jaywcjlove-auto-config-loader-849af3a/config-example/config-dir-toml/.config/000077500000000000000000000000001515666352100272125ustar00rootroot00000000000000jaywcjlove-auto-config-loader-849af3a/config-example/config-dir-toml/.config/autoconfrc.toml000066400000000000000000000005511515666352100322530ustar00rootroot00000000000000# 这是一个 TOML 文档 title = "TOML 示例" [owner] name = "Tom Preston-Werner" dob = 1979-05-27T07:32:00-08:00 [database] enabled = true ports = [ 8000, 8001, 8002 ] data = [ ["delta", "phi"], [3.14] ] temp_targets = { cpu = 79.5, case = 72.0 } [servers] [servers.alpha] ip = "10.0.0.1" role = "前端" [servers.beta] ip = "10.0.0.2" role = "后端"jaywcjlove-auto-config-loader-849af3a/config-example/config-dir-ts/000077500000000000000000000000001515666352100253425ustar00rootroot00000000000000jaywcjlove-auto-config-loader-849af3a/config-example/config-dir-ts/.config/000077500000000000000000000000001515666352100266655ustar00rootroot00000000000000jaywcjlove-auto-config-loader-849af3a/config-example/config-dir-ts/.config/autoconfrc.ts000066400000000000000000000001521515666352100313760ustar00rootroot00000000000000const projectName: 'ext-config-ts' | 'ext-config-ts2' = 'ext-config-ts'; export default { projectName }; jaywcjlove-auto-config-loader-849af3a/config-example/config-dir-yaml/000077500000000000000000000000001515666352100256565ustar00rootroot00000000000000jaywcjlove-auto-config-loader-849af3a/config-example/config-dir-yaml/.config/000077500000000000000000000000001515666352100272015ustar00rootroot00000000000000jaywcjlove-auto-config-loader-849af3a/config-example/config-dir-yaml/.config/autoconfrc.yml000066400000000000000000000002271515666352100320700ustar00rootroot00000000000000%YAML 1.2 --- YAML: YAML Ain't Markup Language™ What It Is: YAML is a human-friendly data serialization language for all programming languages. jaywcjlove-auto-config-loader-849af3a/config-example/config-dir-yml/000077500000000000000000000000001515666352100255155ustar00rootroot00000000000000jaywcjlove-auto-config-loader-849af3a/config-example/config-dir-yml/.config/000077500000000000000000000000001515666352100270405ustar00rootroot00000000000000jaywcjlove-auto-config-loader-849af3a/config-example/config-dir-yml/.config/autoconfrc.yml000066400000000000000000000002271515666352100317270ustar00rootroot00000000000000%YAML 1.2 --- YAML: YAML Ain't Markup Language™ What It Is: YAML is a human-friendly data serialization language for all programming languages. jaywcjlove-auto-config-loader-849af3a/config-example/error-config/000077500000000000000000000000001515666352100252715ustar00rootroot00000000000000jaywcjlove-auto-config-loader-849af3a/config-example/error-config/mjs/000077500000000000000000000000001515666352100260625ustar00rootroot00000000000000jaywcjlove-auto-config-loader-849af3a/config-example/error-config/mjs/.autoconfrc.mjs000066400000000000000000000001201515666352100310070ustar00rootroot00000000000000export default { "dist": path.resolve(process.cwd(), "test/templates/dist2") }jaywcjlove-auto-config-loader-849af3a/config-example/ext-cjs/000077500000000000000000000000001515666352100242525ustar00rootroot00000000000000jaywcjlove-auto-config-loader-849af3a/config-example/ext-cjs/.autoconfrc.cjs000066400000000000000000000000561515666352100271750ustar00rootroot00000000000000module.exports = { projectName: "ext-cjs", }jaywcjlove-auto-config-loader-849af3a/config-example/ext-config-cjs/000077500000000000000000000000001515666352100255155ustar00rootroot00000000000000jaywcjlove-auto-config-loader-849af3a/config-example/ext-config-cjs/autoconf.config.js000066400000000000000000000000671515666352100311400ustar00rootroot00000000000000module.exports = { projectName: 'ext-config-cjs', }; jaywcjlove-auto-config-loader-849af3a/config-example/ext-config-js/000077500000000000000000000000001515666352100253525ustar00rootroot00000000000000jaywcjlove-auto-config-loader-849af3a/config-example/ext-config-js/autoconf.config.js000066400000000000000000000000661515666352100307740ustar00rootroot00000000000000module.exports = { projectName: 'ext-config-js', }; jaywcjlove-auto-config-loader-849af3a/config-example/ext-config-mjs/000077500000000000000000000000001515666352100255275ustar00rootroot00000000000000jaywcjlove-auto-config-loader-849af3a/config-example/ext-config-mjs/autoconf.config.mjs000066400000000000000000000000611515666352100313210ustar00rootroot00000000000000export default { projectName: 'ext-config-mjs' };jaywcjlove-auto-config-loader-849af3a/config-example/ext-config-ts/000077500000000000000000000000001515666352100253645ustar00rootroot00000000000000jaywcjlove-auto-config-loader-849af3a/config-example/ext-config-ts/autoconf.config.ts000066400000000000000000000001521515666352100310140ustar00rootroot00000000000000const projectName: 'ext-config-ts' | 'ext-config-ts2' = 'ext-config-ts'; export default { projectName }; jaywcjlove-auto-config-loader-849af3a/config-example/ext-ini/000077500000000000000000000000001515666352100242525ustar00rootroot00000000000000jaywcjlove-auto-config-loader-849af3a/config-example/ext-ini/.autoconfrc.ini000066400000000000000000000003471515666352100272000ustar00rootroot00000000000000; this comment is being ignored scope = global [database] user = dbuser password = dbpassword database = use_this_database [paths.default] datadir = /var/lib/data array[] = first value array[] = second value array[] = third valuejaywcjlove-auto-config-loader-849af3a/config-example/ext-json/000077500000000000000000000000001515666352100244445ustar00rootroot00000000000000jaywcjlove-auto-config-loader-849af3a/config-example/ext-json/.autoconfrc.json000066400000000000000000000000401515666352100275520ustar00rootroot00000000000000{ "projectName": "ext-json" } jaywcjlove-auto-config-loader-849af3a/config-example/ext-json5/000077500000000000000000000000001515666352100245315ustar00rootroot00000000000000jaywcjlove-auto-config-loader-849af3a/config-example/ext-json5/.autoconfrc.json5000066400000000000000000000004511515666352100277320ustar00rootroot00000000000000{ // 注释 "projectName": "ext-json", name: 'my-app', // 允许使用十六进制和八进制数值 hex: 0x1a, octal: 0o755, // 允许使用 NaN、Infinity 和 -Infinity max: Infinity, min: -Infinity, notANumber: NaN, // 允许使用尾随逗号 'react-dom': '^16.13.1', }jaywcjlove-auto-config-loader-849af3a/config-example/ext-jsonc/000077500000000000000000000000001515666352100246075ustar00rootroot00000000000000jaywcjlove-auto-config-loader-849af3a/config-example/ext-jsonc/.autoconfrc.jsonc000066400000000000000000000000541515666352100300650ustar00rootroot00000000000000{ // 注释 "projectName": "ext-jsonc" }jaywcjlove-auto-config-loader-849af3a/config-example/ext-mjs/000077500000000000000000000000001515666352100242645ustar00rootroot00000000000000jaywcjlove-auto-config-loader-849af3a/config-example/ext-mjs/.autoconfrc.mjs000066400000000000000000000001111515666352100272110ustar00rootroot00000000000000import { projectName } from './data.mjs'; export default { projectName };jaywcjlove-auto-config-loader-849af3a/config-example/ext-mjs/data.mjs000066400000000000000000000000451515666352100257070ustar00rootroot00000000000000export const projectName = "ext-mjs";jaywcjlove-auto-config-loader-849af3a/config-example/ext-toml/000077500000000000000000000000001515666352100244465ustar00rootroot00000000000000jaywcjlove-auto-config-loader-849af3a/config-example/ext-toml/.autoconfrc.toml000066400000000000000000000005511515666352100275650ustar00rootroot00000000000000# 这是一个 TOML 文档 title = "TOML 示例" [owner] name = "Tom Preston-Werner" dob = 1979-05-27T07:32:00-08:00 [database] enabled = true ports = [ 8000, 8001, 8002 ] data = [ ["delta", "phi"], [3.14] ] temp_targets = { cpu = 79.5, case = 72.0 } [servers] [servers.alpha] ip = "10.0.0.1" role = "前端" [servers.beta] ip = "10.0.0.2" role = "后端"jaywcjlove-auto-config-loader-849af3a/config-example/ext-ts/000077500000000000000000000000001515666352100241215ustar00rootroot00000000000000jaywcjlove-auto-config-loader-849af3a/config-example/ext-ts/.autoconfrc.ts000066400000000000000000000001511515666352100267070ustar00rootroot00000000000000export default (name: string): string => { return name + 123; }; export const projectName = 'ext-ts'; jaywcjlove-auto-config-loader-849af3a/config-example/ext-yaml/000077500000000000000000000000001515666352100244355ustar00rootroot00000000000000jaywcjlove-auto-config-loader-849af3a/config-example/ext-yaml/.autoconfrc.yaml000066400000000000000000000002271515666352100275430ustar00rootroot00000000000000%YAML 1.2 --- YAML: YAML Ain't Markup Language™ What It Is: YAML is a human-friendly data serialization language for all programming languages. jaywcjlove-auto-config-loader-849af3a/config-example/ext-yml/000077500000000000000000000000001515666352100242745ustar00rootroot00000000000000jaywcjlove-auto-config-loader-849af3a/config-example/ext-yml/.autoconfrc.yaml000066400000000000000000000002271515666352100274020ustar00rootroot00000000000000%YAML 1.2 --- YAML: YAML Ain't Markup Language™ What It Is: YAML is a human-friendly data serialization language for all programming languages. jaywcjlove-auto-config-loader-849af3a/config-example/js-cjs/000077500000000000000000000000001515666352100240665ustar00rootroot00000000000000jaywcjlove-auto-config-loader-849af3a/config-example/js-cjs/.autoconfrc.js000066400000000000000000000000571515666352100266470ustar00rootroot00000000000000module.exports = { projectName: 'js-cjs', }; jaywcjlove-auto-config-loader-849af3a/config-example/js-esm/000077500000000000000000000000001515666352100240735ustar00rootroot00000000000000jaywcjlove-auto-config-loader-849af3a/config-example/js-esm/.autoconfrc.js000066400000000000000000000000551515666352100266520ustar00rootroot00000000000000export default { projectName: 'js-esm', }; jaywcjlove-auto-config-loader-849af3a/config-example/js-typescript/000077500000000000000000000000001515666352100255155ustar00rootroot00000000000000jaywcjlove-auto-config-loader-849af3a/config-example/js-typescript/.autoconfrc.ts000066400000000000000000000001141515666352100303020ustar00rootroot00000000000000const config = { projectName: 'js-typescript', }; export default config; jaywcjlove-auto-config-loader-849af3a/config-example/pkg-config/000077500000000000000000000000001515666352100247215ustar00rootroot00000000000000jaywcjlove-auto-config-loader-849af3a/config-example/pkg-config/autoconfrc.mjs000066400000000000000000000001271515666352100275770ustar00rootroot00000000000000export default { projectName: 'ext-config-mjs', test: { projectName: "~~~" } };jaywcjlove-auto-config-loader-849af3a/config-example/pkg-config/package.json000066400000000000000000000000561515666352100272100ustar00rootroot00000000000000{ "autoconf": { "name": "autoconf" } }jaywcjlove-auto-config-loader-849af3a/config-example/pkg/000077500000000000000000000000001515666352100234565ustar00rootroot00000000000000jaywcjlove-auto-config-loader-849af3a/config-example/pkg/package.json000066400000000000000000000000561515666352100257450ustar00rootroot00000000000000{ "autoconf": { "name": "autoconf" } }jaywcjlove-auto-config-loader-849af3a/core/000077500000000000000000000000001515666352100207275ustar00rootroot00000000000000jaywcjlove-auto-config-loader-849af3a/core/README.md000066400000000000000000000513371515666352100222170ustar00rootroot00000000000000
Using my app is also a way to support me:
Scap: Screenshot & Markup Edit Screen Test Deskmark Keyzer Vidwall Hub VidCrop Vidwall Mousio Hint Mousio Musicer Audioer FileSentinel FocusCursor Videoer KeyClicker DayBar Iconed Mousio Quick RSS Quick RSS Web Serve Copybook Generator DevTutor for SwiftUI RegexMate Time Passage Iconize Folder Textsound Saver Create Custom Symbols DevHub Resume Revise Palette Genius Symbol Scribe

Auto Config Loader === [![Buy me a coffee](https://img.shields.io/badge/Buy_Me_a_Coffee-ffdd00?logo=buy-me-a-coffee&logoColor=black)](https://jaywcjlove.github.io/#/sponsor) [![Follow On X](https://img.shields.io/badge/Follow%20on%20X-333333?logo=x&logoColor=white)](https://x.com/jaywcjlove) [![CI](https://github.com/jaywcjlove/auto-config-loader/actions/workflows/main.yml/badge.svg)](https://github.com/jaywcjlove/auto-config-loader/actions/workflows/main.yml) [![NPM version](https://img.shields.io/npm/v/auto-config-loader.svg?style=flat&label=npm)](https://npmjs.org/package/auto-config-loader) [![Coverage Status](https://jaywcjlove.github.io/auto-config-loader/badges.svg)](https://jaywcjlove.github.io/auto-config-loader/lcov-report/) [![npm Downloads](https://img.shields.io/npm/dm/auto-config-loader?style=flat)](https://www.npmjs.com/package/auto-config-loader) Find and load configuration from a `package.json` property, `rc` file, or `CommonJS` module. It has smart default based on traditional expectations in the JavaScript ecosystem. But it's also flexible enough to search anywhere you want and load whatever you want. [V1 To V2 Migration](#v1-to-v2-migration) ## Features - Support [JSON](https://www.json.org), [JSONC](https://github.com/microsoft/node-jsonc-parser), [JSON5](https://json5.org/), [YAML](https://yaml.org/), [TOML](https://toml.io), [INI](https://en.wikipedia.org/wiki/INI_file), [CJS](http://www.commonjs.org), [Typescript](https://www.typescriptlang.org/), and ESM config load. - Reads config from the nearest `package.json` file ## Install ```bash $ npm i auto-config-loader ``` ## Quick start ```js const autoConf = require('auto-config-loader'); import { autoConf } from 'auto-config-loader'; // will look for: // process.cwd() + '.namespacerc' // process.cwd() + '.namespacerc.js' // process.cwd() + '.namespacerc.ts' // process.cwd() + '.namespacerc.mjs' // process.cwd() + '.namespacerc.cjs' // process.cwd() + '.namespacerc.json' // process.cwd() + '.namespacerc.json5' // process.cwd() + '.namespacerc.jsonc' // process.cwd() + '.namespacerc.yaml' // process.cwd() + '.namespacerc.yml' // process.cwd() + '.namespacerc.toml' // process.cwd() + 'namespace.config.mjs' // process.cwd() + 'namespace.config.cjs' // process.cwd() + 'namespace.config.js' // ........ const data = await autoConf('namespace', { default: { testItem2: 'some value' } }); ``` ## Load JS Load the JS file and return the result, support `.js`, `.cjs`, `.mjs`, `.ts`. ```js // => ./app/app.config.js export default { name: 'app' } ``` ```ts import { loadConf } from 'auto-config-loader/load-conf'; interface Config { name: string; } const result = await loadConf('./app/app.config.js'); // => { name: 'app' } ``` ## Option ```ts import { LoadConfOption } from 'auto-config-loader'; export type LoaderFunc = (filepath: string, content: string, jsOption?: LoadConfOption) => T | Promise; export type Loader = Record>; export interface AutoConfOption { searchPlaces?: string[]; /** An object that maps extensions to the loader functions responsible for loading and parsing files with those extensions. */ loaders?: Loader; /** Specify default configuration. It has the lowest priority and is applied after extending config. */ default?: T; /** Resolve configuration from this working directory. The default is `process.cwd()` */ cwd?: string; /** Default transform js configuration */ jsOption?: LoadConfOption; /** @deprecated use `mustExist` instead */ ignoreLog?: boolean; mustExist?: boolean; } export declare const getConfigPath: () => string; /** * Find and load configuration from a `package.json` property, `rc` file, or `CommonJS` module. * @param namespace {string} Configuration base name. The default is `autoconf`. * @param option */ export declare function autoConf(namespace?: string, option?: AutoConfOption): Promise<{} & T>; export default autoConf; ``` Discover configurations in the specified directory order. When configuring a tool, you can use multiple file formats and put these in multiple places. Usually, a tool would mention this in its own README file, but by default, these are the following places, where `${moduleName}` represents the name of the tool: **Default `searchPlaces`:** ```js [ 'package.json', `.${moduleName}rc`, `.${moduleName}rc.json`, `.${moduleName}rc.json5`, `.${moduleName}rc.jsonc`, `.${moduleName}rc.yaml`, `.${moduleName}rc.yml`, `.${moduleName}rc.toml`, `.${moduleName}rc.ini`, `.${moduleName}rc.js`, `.${moduleName}rc.ts`, `.${moduleName}rc.cjs`, `.${moduleName}rc.mjs`, `.config/${moduleName}rc`, `.config/${moduleName}rc.json`, `.config/${moduleName}rc.json5`, `.config/${moduleName}rc.jsonc`, `.config/${moduleName}rc.yaml`, `.config/${moduleName}rc.yml`, `.config/${moduleName}rc.toml`, `.config/${moduleName}rc.ini`, `.config/${moduleName}rc.js`, `.config/${moduleName}rc.ts`, `.config/${moduleName}rc.cjs`, `.config/${moduleName}rc.mjs`, `${moduleName}.config.js`, `${moduleName}.config.ts`, `${moduleName}.config.cjs`, `${moduleName}.config.mjs`, ] ``` Configurations are loaded sequentially, and the configuration file search is terminated when a configuration file exists. The content of these files is defined by the tool. For example, you can add a `semi` configuration value to `false` using a file called `.config/autoconfig.yml`: ```yml semi: true ``` Additionally, you have the option to put a property named after the tool in your `package.json` file, with the contents of that property being the same as the file contents. To use the same example as above: ```js { "name": "your-project", "autoconfig": { "semi": true } } ``` This has the advantage that you can put the configuration of all tools (at least the ones that use `auto-config-loader`) in one file. ## Loader ### `.js`,`.ts`,`.cjs`,`.mjs` ```ts import type jiti from 'jiti'; import { Options } from 'sucrase'; type Jiti = ReturnType; type JITIOptions = Jiti['options']; export interface LoadConfOption { jiti?: boolean; jitiOptions?: JITIOptions; transformOption?: Options; } export declare function loadConf(path: string, option?: LoadConfOption): Promise; export declare function jsLoader( filepath: string, content: string, option?: LoadConfOption ): Promise; ``` Modify default `.js`,`.ts`,`.cjs`,`.mjs` loader parameters. ```js import load, { jsLoader } from 'auto-config-loader'; function loadJS(filepath, content) { return jsLoader(filepath, content, { // change option... }); } const data = await load('namespace', { loaders: { '.js': loadJS, '.ts': loadJS, '.cjs': loadJS, '.mjs': loadJS, }, default: { testItem2: 'some value' } }); ``` example: ```ts import { jsLoader } from 'auto-config-loader'; const data = jsLoader('/path/to/file/name.js') ``` ### `.ini` ```ts export declare function iniLoader(_: string, content: string): T; ``` example: ```ts import { iniLoader } from 'auto-config-loader'; const data = iniLoader(undefined, `...`) ``` ### `.json`,`.jsonc`, `json5` ```ts export declare function jsonLoader(_: string, content: string): T; ``` example: ```ts import { jsonLoader } from 'auto-config-loader'; const data = jsonLoader(undefined, `{ "a": 123 }`) ``` ### `.toml` ```ts export declare function tomlLoader(_: string, content: string): T; ``` example: ```ts import { tomlLoader } from 'auto-config-loader'; const data = tomlLoader(undefined, `...`) ``` ### `.yaml` ```ts export declare function yamlLoader(_: string, content: string): T; ``` example: ```ts import { yamlLoader } from 'auto-config-loader'; const data = yamlLoader(undefined, `...`) ``` ## Custom `Yaml` loader This is an example, the default `yaml`/`yml` does not require a loader. ```js import load from 'auto-config-loader'; import yaml from 'yaml'; function loadYaml(filepath, content) { return yaml.parse(content); } const data = await load('namespace', { searchPlaces: [ '.namespacerc.yaml', '.namespacerc.yml', ], loaders: { '.yaml': loadYaml, '.yml': loadYaml, }, default: { testItem2: 'some value' } }); ``` ## Utils ### merge ```ts export declare const merge: { (object: TObject, source: TSource): TObject & TSource; (object: TObject, source1: TSource1, source2: TSource2): TObject & TSource1 & TSource2; (object: TObject, source1: TSource1, source2: TSource2, source3: TSource3): TObject & TSource1 & TSource2 & TSource3; (object: TObject, source1: TSource1, source2: TSource2, source3: TSource3, source4: TSource4): TObject & TSource1 & TSource2 & TSource3 & TSource4; (object: any, ...otherArgs: any[]): any; }; ``` ### findConfigFile ```ts export declare function findConfigFile( moduleName: string, root: string, searchPlaces?: string[] ): string; ``` ### getConfigPath ```ts export declare const getConfigPath: () => string; ``` Example: ```ts import { autoConf, getConfigPath } from 'auto-config-loader'; const data = autoConf('idoc'); const configPath = getConfigPath(); // => /.autoconfrc.js ``` ## V1 To V2 Migration This guide provides the steps to migrate to the latest version of the configuration loader API. ### Key Changes 1. **Loader Functions Support Async** - `LoaderFunc` now supports returning `T` or `Promise`. - Update custom loaders to handle asynchronous operations if needed. **Example:** ```ts export type LoaderFunc = ( filepath: string, content: string, jsOption?: LoadConfOption ) => T | Promise; ``` 2. **`autoConf` Returns a Promise** - The `autoConf` function now returns a `Promise` instead of a synchronous result. - Update your code to handle asynchronous calls. **Example:** ```ts export declare function autoConf( namespace?: string, option?: AutoConfOption ): Promise<{} & T>; ``` ### Migration Steps #### 1. Update Custom Loader Functions If you have custom loaders, update their return types to support asynchronous operations: **Example:** ```ts const jsonLoader: LoaderFunc = async ( filepath, content ) => JSON.parse(content); ``` #### 2. Handle Asynchronous `autoConf` Calls Update all calls to `autoConf` to use `await` or `.then` to handle Promises: **Example Using `await`:** ```ts const config = await autoConf('myNamespace', options); console.log(config); ``` **Example Using `.then`:** ```ts autoConf('myNamespace', options).then(config => { console.log(config); }); ``` ## Related - [cosmiconfig](https://github.com/cosmiconfig/cosmiconfig) Find and load configuration from a package.json property, rc file, or CommonJS module - [cjson](https://www.npmjs.com/package/cjson) Comments enabled json loader (Commented JavaScript Object Notation) - [Config Loader](https://www.npmjs.com/package/@web/config-loader) Load user config files for node js projects. - [Lilconfig](https://www.npmjs.com/package/lilconfig) Zero-dependency nodejs config seeker. - [proload](https://github.com/natemoo-re/proload) Searches for and loads your tool's JavaScript configuration files with full support for CJS, ESM, TypeScript and more. - [rc](https://github.com/dominictarr/rc) The non-configurable configuration loader for lazy people. Library | Last commit | Download | loaders | config ext :-- | --- | --- | --- | --- **auto-config-loader** | [![GitHub last commit](https://img.shields.io/github/last-commit/jaywcjlove/auto-config-loader?style=flat&label=)](https://github.com/jaywcjlove/auto-config-loader/commits) | [![NPM Downloads](https://img.shields.io/npm/dm/auto-config-loader.svg?style=flat&label=)](https://www.npmjs.com/package/auto-config-loader) | ✅ | `.js`, `.ts`, `.cjs`, `.mjs`, `.json`, `.jsonc`, `json5`, `.ini`, `.toml`, `.yaml` ++ cosmiconfig | [![GitHub last commit](https://img.shields.io/github/last-commit/cosmiconfig/cosmiconfig?style=flat&label=)](https://github.com/cosmiconfig/cosmiconfig/commits) | [![NPM Downloads](https://img.shields.io/npm/dm/cosmiconfig.svg?style=flat&label=)](https://www.npmjs.com/package/cosmiconfig) | ✅ | `.json`, `.yaml`, `.yml`, `.js`, `.mjs`, `.cjs` ~~rc~~ | [![GitHub last commit](https://img.shields.io/github/last-commit/dominictarr/rc?style=flat&label=)](https://github.com/dominictarr/rc/commits) | [![NPM Downloads](https://img.shields.io/npm/dm/rc.svg?style=flat&label=)](https://www.npmjs.com/package/rc) | ✅ | `.json`, `.yaml`, `.yml`, `.js`, `.mjs`, `.cjs` @proload/core | [![GitHub last commit](https://img.shields.io/github/last-commit/natemoo-re/proload?style=flat&label=)](https://github.com/natemoo-re/proload/commits) | [![NPM Downloads](https://img.shields.io/npm/dm/@proload/core.svg?style=flat&label=)](https://www.npmjs.com/package/@proload/core) | ✅ | `.js`, `.ts`, `.cjs`, `.mjs`, `.json`, `.jsonc`, `json5`, `.ini`, `.toml`, `.yaml` ++ lilconfig | [![GitHub last commit](https://img.shields.io/github/last-commit/antonk52/lilconfig?style=flat&label=)](https://github.com/antonk52/lilconfig/commits) | [![NPM Downloads](https://img.shields.io/npm/dm/lilconfig.svg?style=flat&label=)](https://www.npmjs.com/package/lilconfig) | ✅ | `.js`, `.cjs`, `.mjs`, `.json` ++ ~~cjson~~ | [![GitHub last commit](https://img.shields.io/github/last-commit/kof/node-cjson?style=flat&label=)](https://github.com/kof/node-cjson/commits) | [![NPM Downloads](https://img.shields.io/npm/dm/cjson.svg?style=flat&label=)](https://www.npmjs.com/package/cjson) | ✅ | `.json` @web/config-loader | [![GitHub last commit](https://img.shields.io/github/last-commit/modernweb-dev/web?style=flat&label=)](https://github.com/modernweb-dev/web/commits) | [![NPM Downloads](https://img.shields.io/npm/dm/@web/config-loader.svg?style=flat&label=)](https://www.npmjs.com/package/@web/config-loader) | ❌ | `.js`, `.mjs`, `.cjs` ## Contributors As always, thanks to our amazing contributors! Made with [contributors](https://github.com/jaywcjlove/github-action-contributors). ## License This package is licensed under the MIT License. jaywcjlove-auto-config-loader-849af3a/core/load-conf.d.ts000066400000000000000000000001651515666352100233650ustar00rootroot00000000000000export declare function loadConf(path: string): T; export declare function importDefault(filepath: string): T; jaywcjlove-auto-config-loader-849af3a/core/package.json000066400000000000000000000034171515666352100232220ustar00rootroot00000000000000{ "name": "auto-config-loader", "version": "3.0.4", "description": "Find and load configuration from a package.json property, rc file, or CommonJS module.", "main": "./lib/index.js", "type": "commonjs", "types": "./lib/index.d.ts", "exports": { ".": { "require": "./lib/index.js", "import": "./lib/index.js", "types": "./lib/index.d.ts" }, "./load-conf": { "require": "./lib/loader/js.js", "import": "./lib/loader/js.js", "types": "./lib/loader/js.d.ts" } }, "homepage": "https://jaywcjlove.github.io/auto-config-loader", "funding": "https://jaywcjlove.github.io/#/sponsor", "repository": { "type": "git", "url": "https://github.com/jaywcjlove/auto-config-loader.git" }, "scripts": { "watch": "tsbb watch", "build": "tsbb build", "test": "tsbb test", "coverage": "tsbb test --coverage --bail" }, "keywords": [ "rc", "config", "loader", "load", "configuration", "cjs", "commonjs", "esm", "es module", "yml-config", "js-config", "ts-config", "toml-config", "yml", "js", "ts", "toml", "typescript", "config-loader", "auto-config-loader" ], "author": "jaywcjlove", "license": "MIT", "files": [ "load-conf.d.ts", "lib", "src" ], "jest": { "transformIgnorePatterns": [ "/node_modules/?!(.*)" ] }, "engines": { "node": "^20.17.0 || >=22.9.0" }, "dependencies": { "ini": "^6.0.0", "jiti": "^2.6.1", "jsonc-eslint-parser": "^2.4.1", "lodash.merge": "^4.6.2", "sucrase": "^3.35.1", "toml-eslint-parser": "^0.10.0", "yaml-eslint-parser": "^1.3.0" }, "devDependencies": { "@types/ini": "^4.0.0", "@types/lodash.merge": "^4.6.9" } } jaywcjlove-auto-config-loader-849af3a/core/src/000077500000000000000000000000001515666352100215165ustar00rootroot00000000000000jaywcjlove-auto-config-loader-849af3a/core/src/index.ts000066400000000000000000000071631515666352100232040ustar00rootroot00000000000000import fs from 'fs'; import path from 'path'; import mergeFun from 'lodash.merge'; import { jsLoader, LoadConfOption } from './loader/js'; import { jsonLoader } from './loader/json'; import { yamlLoader } from './loader/yaml'; import { tomlLoader } from './loader/toml'; import { iniLoader } from './loader/ini'; import { findConfigFile } from './utils'; export * from './utils'; export * from './loader/js'; export * from './loader/json'; export * from './loader/yaml'; export * from './loader/toml'; export * from './loader/ini'; export const merge = mergeFun; export type LoaderFunc = (filepath: string, content: string, jsOption?: LoadConfOption) => T | Promise; export type Loader = Record>; export interface AutoConfOption { searchPlaces?: string[]; /** An object that maps extensions to the loader functions responsible for loading and parsing files with those extensions. */ loaders?: Loader; /** Specify default configuration. It has the lowest priority and is applied after extending config. */ default?: T; /** Resolve configuration from this working directory. The default is `process.cwd()` */ cwd?: string; /** Default transform js configuration */ jsOption?: LoadConfOption; /** @deprecated use `mustExist` instead */ ignoreLog?: boolean; mustExist?: boolean; } let configPath = ''; export const getConfigPath = () => configPath; /** * Find and load configuration from a `package.json` property, `rc` file, or `CommonJS` module. * @param namespace {string} Configuration base name. The default is `autoconf`. * @param option */ export async function autoConf(namespace: string = 'autoconf', option: AutoConfOption = {}) { const { searchPlaces = [], default: defaultValue = {}, cwd = process.cwd(), ignoreLog = false, mustExist = ignoreLog || false, jsOption, } = option; const loaders: Loader = { '.yml': yamlLoader, '.yaml': yamlLoader, '.ini': iniLoader, '.toml': tomlLoader, '.json': jsonLoader, '.json5': jsonLoader, '.jsonc': jsonLoader, '.js': jsLoader, '.ts': jsLoader, '.cjs': jsLoader, '.mjs': jsLoader, ...(option.loaders || {}), }; const pkgPath = path.resolve(cwd, 'package.json'); configPath = findConfigFile(namespace, cwd, searchPlaces); let content = ''; let resultData: T; let loaderFunc: LoaderFunc; try { if (configPath) { const extname = path.extname(configPath); const basename = path.basename(configPath); if (new RegExp(`^(.?${namespace}rc)$`).test(basename)) { content = fs.readFileSync(configPath, 'utf-8'); loaderFunc = loaders['.json']; } else if (loaders[extname]) { content = fs.readFileSync(configPath, 'utf-8'); loaderFunc = loaders[extname]; } } let pkgContent: T; if (fs.existsSync(pkgPath)) { content = fs.readFileSync(pkgPath, 'utf-8'); const result = loaders['.json'](pkgPath, content); pkgContent = (result as Record)[namespace]; } if (content && loaderFunc) { resultData = await loaderFunc(configPath, content, jsOption); if (typeof resultData === 'function') { return merge(defaultValue, resultData ?? {}, { ...pkgContent }, { default: resultData }); } } if (pkgContent) { return merge(defaultValue, { ...resultData }, { ...pkgContent }); } if (!!mustExist && !configPath && !resultData) { return null; } return merge(defaultValue, { ...resultData }, { ...pkgContent }); } catch (error) { console.log(`AUTO_CONF:CATCH:ERROR: \x1b[31;1m${error}\x1b[0m`); } } export default autoConf; jaywcjlove-auto-config-loader-849af3a/core/src/loader/000077500000000000000000000000001515666352100227645ustar00rootroot00000000000000jaywcjlove-auto-config-loader-849af3a/core/src/loader/ini.ts000066400000000000000000000001721515666352100241130ustar00rootroot00000000000000import ini from 'ini'; export function iniLoader(_: string, content: string): T { return ini.parse(content) as T; } jaywcjlove-auto-config-loader-849af3a/core/src/loader/js.ts000066400000000000000000000036211515666352100237520ustar00rootroot00000000000000import { createJiti } from 'jiti'; import type jiti from 'jiti'; import { transform, Options } from 'sucrase'; type Jiti = ReturnType; type JITIOptions = Jiti['options']; let jitiInstance: ReturnType | null = null; function lazyJiti(option: JITIOptions = {}, transformOpt = {} as Options) { return ( jitiInstance ?? (jitiInstance = createJiti(__filename, { interopDefault: true, ...option, transform: (opts) => { return transform(opts.source, { transforms: ['typescript', 'imports'], ...transformOpt, }); }, })) ); } export interface LoadConfOption { jiti?: boolean; jitiOptions?: JITIOptions; transformOption?: Options; } export async function loadConf(path: string, option: LoadConfOption = {}): Promise { const { jiti = true, jitiOptions, transformOption } = option; let config = await (async function () { try { if (jiti) { return path ? await lazyJiti(jitiOptions, transformOption).import(path) : {}; } else { return path ? require(path) : {}; } } catch { return await lazyJiti(jitiOptions, transformOption).import(path); } })(); // Ensure both default export and named exports are handled if (config.default) { if (typeof config.default === 'function') { const defaultFunc = config.default; Object.assign(defaultFunc, config); return defaultFunc; } else { config = { ...config.default, ...config }; } } // ⚠️ 🚨 For some reason, the CI test default does not exist on the Windows platform. // To ensure platform consistency, default has been removed. if (path && path.endsWith('.cjs')) { delete config.default; } return config; } export async function jsLoader(filepath: string, content: string, option: LoadConfOption = {}): Promise { return await loadConf(filepath, option); } jaywcjlove-auto-config-loader-849af3a/core/src/loader/json.ts000066400000000000000000000004211515666352100243020ustar00rootroot00000000000000import type { AST } from 'jsonc-eslint-parser'; import { parseJSON, getStaticJSONValue } from 'jsonc-eslint-parser'; export function jsonLoader(_: string, content: string): T { const ast: AST.JSONProgram = parseJSON(content); return getStaticJSONValue(ast) as T; } jaywcjlove-auto-config-loader-849af3a/core/src/loader/toml.ts000066400000000000000000000004171515666352100243110ustar00rootroot00000000000000import type { AST } from 'toml-eslint-parser'; import { parseTOML, getStaticTOMLValue } from 'toml-eslint-parser'; export function tomlLoader(_: string, content: string): T { const ast: AST.TOMLProgram = parseTOML(content); return getStaticTOMLValue(ast) as T; } jaywcjlove-auto-config-loader-849af3a/core/src/loader/yaml.ts000066400000000000000000000004171515666352100243000ustar00rootroot00000000000000import type { AST } from 'yaml-eslint-parser'; import { parseYAML, getStaticYAMLValue } from 'yaml-eslint-parser'; export function yamlLoader(_: string, content: string): T { const ast: AST.YAMLProgram = parseYAML(content); return getStaticYAMLValue(ast) as T; } jaywcjlove-auto-config-loader-849af3a/core/src/utils.ts000066400000000000000000000023201515666352100232230ustar00rootroot00000000000000import path from 'path'; import fs from 'fs'; export function findConfigFile(moduleName: string, root: string, searchPlaces: string[] = []) { const data = [ ...searchPlaces, `.${moduleName}rc`, `.${moduleName}rc.json`, `.${moduleName}rc.json5`, `.${moduleName}rc.jsonc`, `.${moduleName}rc.yaml`, `.${moduleName}rc.yml`, `.${moduleName}rc.toml`, `.${moduleName}rc.ini`, `.${moduleName}rc.js`, `.${moduleName}rc.ts`, `.${moduleName}rc.cjs`, `.${moduleName}rc.mjs`, `.config/${moduleName}rc`, `.config/${moduleName}rc.json`, `.config/${moduleName}rc.json5`, `.config/${moduleName}rc.jsonc`, `.config/${moduleName}rc.yaml`, `.config/${moduleName}rc.yml`, `.config/${moduleName}rc.toml`, `.config/${moduleName}rc.ini`, `.config/${moduleName}rc.js`, `.config/${moduleName}rc.ts`, `.config/${moduleName}rc.cjs`, `.config/${moduleName}rc.mjs`, `${moduleName}.config.js`, `${moduleName}.config.ts`, `${moduleName}.config.cjs`, `${moduleName}.config.mjs`, ]; for (const file of data) { const filePath = path.resolve(root, file); if (fs.existsSync(filePath)) { return filePath; } } return null; } jaywcjlove-auto-config-loader-849af3a/core/test/000077500000000000000000000000001515666352100217065ustar00rootroot00000000000000jaywcjlove-auto-config-loader-849af3a/core/test/config.test.ts000066400000000000000000000263111515666352100245040ustar00rootroot00000000000000import path from 'path'; import autoConf from '../src'; import { autoConf as confLoad } from '../src'; test('Loader .autoconfrc', async () => { const data = await autoConf<{ one: number; }>(undefined, { cwd: path.resolve(__dirname, '../../config-example'), }); expect(data?.one).toBe(123); }); test('Loader .autoconfrc', async () => { const data = await confLoad<{ one: number; }>(undefined, { cwd: path.resolve(__dirname, '../../config-example'), }); expect(data?.one).toBe(123); }); test('Loader .autoconfrc.json', async () => { const data = await autoConf<{ name: string; }>(undefined, { cwd: path.resolve(__dirname, '../../config-example/autoconfrcjson'), }); expect(data?.name).toBe('auto-conf'); }); test('Loader .autoconfrc.json', async () => { const data = await autoConf<{ projectName: string; }>(undefined, { cwd: path.resolve(__dirname, '../../config-example/ext-json'), }); expect(data?.projectName).toBe('ext-json'); }); test('Loader .autoconfrc.json5', async () => { const data = await autoConf(undefined, { cwd: path.resolve(__dirname, '../../config-example/ext-json5'), }); expect(data?.projectName).toBe('ext-json'); expect(data?.name).toBe('my-app'); expect(data?.max).toBe(Infinity); expect(data?.min).toBe(-Infinity); expect(data?.notANumber).toBe(NaN); }); test('Loader .config/autoconfrc.json5', async () => { const data = await autoConf(undefined, { cwd: path.resolve(__dirname, '../../config-example/config-dir-json5'), }); expect(data?.projectName).toBe('ext-json'); expect(data?.name).toBe('my-app'); expect(data?.max).toBe(Infinity); expect(data?.min).toBe(-Infinity); expect(data?.notANumber).toBe(NaN); }); test('Loader .config/autoconfrc.jsonc', async () => { const data = await autoConf(undefined, { cwd: path.resolve(__dirname, '../../config-example/config-dir-jsonc'), }); expect(data?.projectName).toBe('ext-jsonc'); }); test('Loader .autoconfrc.jsonc', async () => { const data = await autoConf<{ projectName: string; }>(undefined, { cwd: path.resolve(__dirname, '../../config-example/ext-jsonc'), }); expect(data?.projectName).toBe('ext-jsonc'); }); test('Loader .autoconfrc.js ESM', async () => { const data = await autoConf<{ projectName: string; }>(undefined, { cwd: path.resolve(__dirname, '../../config-example/js-esm'), }); expect(data?.projectName).toBe('js-esm'); }); test('Loader .autoconfrc.mjs EXT ESM', async () => { const data = await autoConf<{ projectName: string; }>(undefined, { cwd: path.resolve(__dirname, '../../config-example/ext-mjs'), }); expect(data?.projectName).toBe('ext-mjs'); }); test('Loader .autoconfrc.js CJS', async () => { const data = await autoConf<{ projectName: string; }>(undefined, { cwd: path.resolve(__dirname, '../../config-example/js-cjs'), }); expect(data?.projectName).toBe('js-cjs'); }); test('Loader .autoconfrc.cjs EXT CJS', async () => { const data = await autoConf<{ projectName: string; }>(undefined, { cwd: path.resolve(__dirname, '../../config-example/js-cjs'), }); expect(data?.projectName).toBe('js-cjs'); }); test('Loader .autoconfrc.ts TypeScript', async () => { const data = await autoConf<{ projectName: string; }>(undefined, { cwd: path.resolve(__dirname, '../../config-example/ext-cjs'), }); expect(data?.projectName).toBe('ext-cjs'); }); test('Loader pkg/package.json', async () => { const data = await autoConf<{ name: string; }>(undefined, { cwd: path.resolve(__dirname, '../../config-example/pkg'), }); expect(data?.name).toBe('autoconf'); }); test('Loader pkg-config/package.json', async () => { const data = await autoConf<{ projectName: string; test: { projectName: string; }; name: string; }>("autoconf", { mustExist: true, cwd: path.resolve(__dirname, '../../config-example/pkg-config'), default: { projectName: "test", test: { projectName: "~~~" }, name: "xx" }, }); expect(data?.projectName).toBe('test'); expect(data?.test.projectName).toBe('~~~'); expect(data?.name).toBe('autoconf'); }); test('Loader autoconf.config.js CJS', async () => { const data = await autoConf<{ projectName: string; }>(undefined, { cwd: path.resolve(__dirname, '../../config-example/ext-config-js'), }); expect(data?.projectName).toBe('ext-config-js'); }); test('Loader autoconf.config.mjs', async () => { const data = await autoConf<{ projectName: string; }>(undefined, { cwd: path.resolve(__dirname, '../../config-example/ext-config-mjs'), }); expect(data?.projectName).toBe('ext-config-mjs'); }); test('Loader autoconf.config.cjs', async () => { const data = await autoConf<{ projectName: string; }>(undefined, { cwd: path.resolve(__dirname, '../../config-example/ext-config-cjs'), }); expect(data?.projectName).toBe('ext-config-cjs'); }); test('Loader autoconf.config.ts', async () => { const data = await autoConf<{ projectName: string; }>(undefined, { cwd: path.resolve(__dirname, '../../config-example/ext-config-ts'), }); expect(data?.projectName).toBe('ext-config-ts'); }); test('Loader .config/autoconfrc', async () => { const data = await autoConf<{ one: number; }>(undefined, { cwd: path.resolve(__dirname, '../../config-example/config-dir-rc'), }); expect(data?.one).toBe(123); }); test('Loader .config/autoconfrc.json', async () => { const data = await autoConf<{ one?: number; projectName?: string; }>(undefined, { default: { projectName: 'name' }, cwd: path.resolve(__dirname, '../../config-example/config-dir-rc'), }); expect(data).toEqual({ one: 123, projectName: 'name' }); }); test('Loader .config/autoconfrc.mjs', async () => { const data = await autoConf<{ one?: number; projectName?: string; }>(undefined, { default: { projectName: 'name' }, cwd: path.resolve(__dirname, '../../config-example/config-dir-mjs'), }); expect(data).toEqual({ default: { projectName: 'ext-config-mjs' }, projectName: 'ext-config-mjs' }); }); test('Loader .config/autoconfrc.cjs', async () => { const data = await autoConf<{ projectName?: string; }>(undefined, { default: { projectName: 'name' }, cwd: path.resolve(__dirname, '../../config-example/config-dir-cjs'), }); expect(data).toEqual({ projectName: 'ext-config-cjs' }); }); test('Loader .config/autoconfrc.js', async () => { const data = await autoConf<{ one?: number; projectName?: string; }>(undefined, { default: { projectName: 'name' }, cwd: path.resolve(__dirname, '../../config-example/config-dir-js'), }); expect(data).toEqual({ default: { projectName: 'ext-config-js' }, projectName: 'ext-config-js' }); }); test('Loader .config/autoconfrc.ts', async () => { const data = await autoConf<{ one?: number; projectName?: string; }>(undefined, { default: { projectName: 'name' }, cwd: path.resolve(__dirname, '../../config-example/config-dir-ts'), }); expect(data).toEqual({ default: { projectName: 'ext-config-ts' }, projectName: 'ext-config-ts' }); }); test('Loader .autoconfrc.yaml', async () => { const data = await autoConf<{ one?: number; projectName?: string; }>(undefined, { cwd: path.resolve(__dirname, '../../config-example/ext-yaml'), }); expect(data).toEqual({ YAML: "YAML Ain't Markup Language™", 'What It Is': 'YAML is a human-friendly data serialization language for all programming languages.' }); }); test('Loader .autoconfrc.yml', async () => { const data = await autoConf<{ one?: number; projectName?: string; }>(undefined, { cwd: path.resolve(__dirname, '../../config-example/ext-yml'), }); expect(data).toEqual({ YAML: "YAML Ain't Markup Language™", 'What It Is': 'YAML is a human-friendly data serialization language for all programming languages.' }); }); test('Loader .config/autoconfrc.yml', async () => { const data = await autoConf<{ one?: number; projectName?: string; }>(undefined, { cwd: path.resolve(__dirname, '../../config-example/config-dir-yml'), }); expect(data).toEqual({ YAML: "YAML Ain't Markup Language™", 'What It Is': 'YAML is a human-friendly data serialization language for all programming languages.' }); }); test('Loader .config/autoconfrc.yaml', async () => { const data = await autoConf<{ one?: number; projectName?: string; }>(undefined, { cwd: path.resolve(__dirname, '../../config-example/config-dir-yaml'), }); expect(data).toEqual({ YAML: "YAML Ain't Markup Language™", 'What It Is': 'YAML is a human-friendly data serialization language for all programming languages.' }); }); const tomlData = { title: 'TOML 示例', owner: { name: "Tom Preston-Werner", dob: new Date('1979-05-27T07:32:00-08:00') }, database: { enabled: true, ports: [ 8000, 8001, 8002 ], data: [ ["delta", "phi"], [3.14] ], temp_targets: { cpu: 79.5, case: 72.0 }, }, servers: { alpha: { ip: "10.0.0.1", role: "前端" }, beta: { ip: "10.0.0.2", role: "后端" }, } } test('Loader .autoconfrc.toml', async () => { const data = await autoConf<{ one?: number; projectName?: string; }>(undefined, { cwd: path.resolve(__dirname, '../../config-example/ext-toml'), }); expect(data).toEqual(tomlData); }); test('Loader .config/autoconfrc.toml', async () => { const data = await autoConf<{ one?: number; projectName?: string; }>(undefined, { cwd: path.resolve(__dirname, '../../config-example/config-dir-toml'), }); expect(data).toEqual(tomlData); }); test('Loader .autoconfrc.ts', async () => { const data = await autoConf<{ default?: Function; projectName?: string; }>(undefined, { cwd: path.resolve(__dirname, '../../config-example/ext-ts'), }); expect(data).toHaveProperty(['default']); expect(data?.projectName).toEqual('ext-ts'); }); const iniData = { "database": { "database": "use_this_database", "password": "dbpassword", "user": "dbuser", }, "paths": { "default": { "array": [ "first value", "second value", "third value", ], "datadir": "/var/lib/data", }, }, "scope": "global", } test('Loader .autoconfrc.ini', async () => { const data = await autoConf(undefined, { cwd: path.resolve(__dirname, '../../config-example/ext-ini'), }); expect(data).toEqual(iniData); }); test('Loader .config/autoconfrc.ini', async () => { const data = await autoConf<{ one?: number; projectName?: string; }>(undefined, { cwd: path.resolve(__dirname, '../../config-example/config-dir-ini'), }); expect(data).toEqual(iniData); }); test('Loader .autoconfrc.ts (option={ jiti: false })', async () => { const data = await autoConf<{ default?: Function; projectName?: string; }>(undefined, { cwd: path.resolve(__dirname, '../../config-example/ext-ts'), jsOption: { jiti: false, } }); expect(data).toHaveProperty(['default']); expect(data?.projectName).toEqual('ext-ts'); }); test('Loader cwd = undefined', async () => { const data = await autoConf(); expect(data).toEqual({}); }); test('Loader ignoreLog = true', async () => { console.log = jest.fn(); const data = await autoConf(undefined, { ignoreLog: true }); expect(data).toBeNull(); // @ts-ignore expect(console.log.mock.calls).toHaveLength(0); }); jaywcjlove-auto-config-loader-849af3a/core/test/error.test.ts000066400000000000000000000027221515666352100243700ustar00rootroot00000000000000import path from 'path'; import autoConf from '../src'; test('loadConf test case', async () => { console.log = jest.fn(); const data = await autoConf<{ one: number; }>(undefined, { cwd: path.resolve(__dirname, '../../config-example/12312312'), }); expect(data).toEqual({}); // @ts-ignore // expect(console.log.mock.calls[0][0]).toBe(`AUTO_CONF:ERROR: \x1b[31;1mCan't find config file\x1b[0m`); }); test('loadConf error-config test case, wrong configuration loaded', async () => { console.log = jest.fn(); const data = await autoConf<{ one: number; }>(undefined, { mustExist: true, cwd: path.resolve(__dirname, '../../config-example/error-config/mjs'), }); expect(data).toBeUndefined(); // @ts-ignore expect(console.log.mock.calls[0][0]).toBe(`AUTO_CONF:CATCH:ERROR: \x1b[31;1mReferenceError: path is not defined\x1b[0m`); }); test('loadConf options mustExist=true test case', async () => { console.log = jest.fn(); const data = await autoConf<{ one: number; }>(undefined, { cwd: path.resolve(__dirname, '../../config-example/12312312'), mustExist: true, }); expect(data).toBeNull(); // @ts-ignore expect(console.log.mock.calls).toHaveLength(0); }); test('loadConf options mustExist=false test case', async () => { console.log = jest.fn(); const data = await autoConf<{ one: number; }>(undefined, { cwd: path.resolve(__dirname, '../../config-example/12312312'), mustExist: false, }); expect(data).toEqual({}); }); jaywcjlove-auto-config-loader-849af3a/core/test/loader.test.ts000066400000000000000000000011751515666352100245060ustar00rootroot00000000000000import path from 'path'; import { loadConf } from "../src/loader/js"; const tsPath = path.resolve(__dirname, '../../config-example/ext-ts/.autoconfrc.ts'); test('loadConf test case', async () => { // @ts-ignore expect(loadConf()).resolves.toEqual({}); const result = await loadConf(tsPath); expect(result.projectName).toEqual('ext-ts'); expect(result.default('good')).toEqual('good123'); }); test('loadConf option=jiti=false test case', async () => { const result = await loadConf(tsPath, { jiti: false }); expect(result.projectName).toEqual('ext-ts'); expect(result.default('good')).toEqual('good123'); }); jaywcjlove-auto-config-loader-849af3a/core/test/utils.test.ts000066400000000000000000000007521515666352100244000ustar00rootroot00000000000000import path from 'path'; import { merge, autoConf, getConfigPath } from "../src"; test('merge test case', () => { expect(merge({ a: 1}, { b: 2, a: 3})).toEqual({ a: 3, b: 2}); }); test('getConfigPath test case', async () => { const data = await autoConf<{ projectName: string; }>(undefined, { cwd: path.resolve(__dirname, '../../config-example/ext-json'), }); expect(data?.projectName).toBe('ext-json'); expect(getConfigPath().endsWith('.autoconfrc.json')).toBeTruthy(); });jaywcjlove-auto-config-loader-849af3a/core/tsconfig.json000066400000000000000000000007001515666352100234330ustar00rootroot00000000000000{ "$schema": "http://json.schemastore.org/tsconfig", "include": ["src"], "compilerOptions": { "module": "Node16", "target": "ESNext", "esModuleInterop": true, "declaration": true, "noImplicitAny": true, "resolveJsonModule": true, "strict": false, "emitDecoratorMetadata": true, "experimentalDecorators": true, "sourceMap": false, "skipLibCheck": true, "outDir": "lib", "baseUrl": "." } } jaywcjlove-auto-config-loader-849af3a/lerna.json000066400000000000000000000000611515666352100217700ustar00rootroot00000000000000{ "version": "3.0.4", "packages": ["core"] } jaywcjlove-auto-config-loader-849af3a/package.json000066400000000000000000000015061515666352100222670ustar00rootroot00000000000000{ "private": true, "scripts": { "prepare": "husky", "start": "npm run build --workspace=core", "watch": "npm run watch --workspace=core", "version": "lerna version --exact --force-publish --no-push --no-git-tag-version", "prettier": "prettier --write '**/*.{js,jsx,tsx,ts,less,md,json}'", "clean": "lerna clean --yes" }, "keywords": [], "author": "jaywcjlove", "license": "MIT", "repository": { "type": "git", "url": "https://github.com/jaywcjlove/auto-config-loader.git" }, "engines": { "node": ">=16.0.0" }, "lint-staged": { "*.{js,jsx,ts,tsx,md,json}": [ "prettier --write" ] }, "workspaces": [ "core" ], "dependencies": { "husky": "^9.0.0", "lerna": "8.0.0", "lint-staged": "^15.0.0", "prettier": "^3.0.0", "tsbb": "^4.1.5" } } jaywcjlove-auto-config-loader-849af3a/renovate.json000066400000000000000000000001531515666352100225140ustar00rootroot00000000000000{ "$schema": "https://docs.renovatebot.com/renovate-schema.json", "extends": [ "config:base" ] }