@dword-design/base 12.0.14 → 12.0.16

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -32,6 +32,7 @@ export default async function () {
32
32
  '**/__snapshots__': true
33
33
  }), ...this.config.allowedMatches];
34
34
  const unknownFiles = (_ref = (_globby = globby('**', {
35
+ cwd: this.cwd,
35
36
  dot: true,
36
37
  gitignore: true,
37
38
  ignore: allowedMatches
@@ -1,4 +1,11 @@
1
1
  import { execa } from 'execa';
2
- export default (options = {}) => execa('git-cz', [...(options.allowEmpty ? ['--allow-empty'] : [])], {
3
- stdio: options.log === false ? 'pipe' : 'inherit'
4
- });
2
+ export default function (options) {
3
+ options = {
4
+ log: process.env.NODE_ENV !== 'test',
5
+ ...options
6
+ };
7
+ return execa('git-cz', [...(options.allowEmpty ? ['--allow-empty'] : [])], {
8
+ cwd: this.cwd,
9
+ [options.log ? 'stdio' : 'stderr']: 'inherit'
10
+ });
11
+ }
@@ -2,13 +2,13 @@ import { endent, isEmpty, join, map, mapValues, omit, values } from '@dword-desi
2
2
  import depcheck from 'depcheck';
3
3
  export default async function () {
4
4
  var _this$packageConfig, _this$packageConfig2, _ref, _ref2, _result$dependencies, _ref3, _result$devDependenci, _ref4, _ref5, _result$invalidFiles;
5
- const dependenciesResult = await depcheck('.', {
5
+ const dependenciesResult = await depcheck(this.cwd, {
6
6
  package: (_this$packageConfig = this.packageConfig, omit(['devDependencies'])(_this$packageConfig)),
7
7
  skipMissing: true,
8
8
  ...this.config.depcheckConfig,
9
9
  ignorePatterns: ['*.spec.js', ...(this.config.testRunner === 'playwright' ? ['/fixtures', '/playwright.config.js'] : ['/global-test-hooks.js']), 'package.json', 'eslint.config.js']
10
10
  });
11
- const devDependenciesResult = await depcheck('.', {
11
+ const devDependenciesResult = await depcheck(this.cwd, {
12
12
  package: (_this$packageConfig2 = this.packageConfig, omit(['dependencies'])(_this$packageConfig2)),
13
13
  skipMissing: true,
14
14
  ...this.config.depcheckConfig,
@@ -1,16 +1,17 @@
1
1
  import { execa } from 'execa';
2
2
  import parsePackagejsonName from 'parse-packagejson-name';
3
- export default async function () {
3
+ export default async function (options) {
4
+ options = {
5
+ log: process.env.NODE_ENV !== 'test',
6
+ ...options
7
+ };
4
8
  const packageName = parsePackagejsonName(this.packageConfig.name).fullName;
5
9
  if (this.config.git !== undefined && packageName !== this.config.git.project) {
6
10
  throw new Error(`Package name '${packageName}' has to be equal to repository name '${this.config.git.project}'`);
7
11
  }
8
- await this.config.lint.call(this);
9
- try {
10
- await execa('eslint', ['--fix', '.'], {
11
- all: true
12
- });
13
- } catch (error) {
14
- throw new Error(error.all);
15
- }
12
+ await this.config.lint.call(this, options);
13
+ await execa('eslint', ['--fix', '.'], {
14
+ [options.log ? 'stdio' : 'stderr']: 'inherit',
15
+ cwd: this.cwd
16
+ });
16
17
  }
@@ -1,4 +1,5 @@
1
1
  import { createRequire } from 'node:module';
2
+ import pathLib from 'node:path';
2
3
  import { first, keys } from '@dword-design/functions';
3
4
  import packageName from 'depcheck-package-name';
4
5
  import { execa, execaCommand } from 'execa';
@@ -6,12 +7,22 @@ import fs from 'fs-extra';
6
7
  import outputFiles from 'output-files';
7
8
  const _require = createRequire(import.meta.url);
8
9
  const commitlintPackageConfig = _require(packageName`@commitlint/cli/package.json`);
9
- export default async function () {
10
- await outputFiles(this.generatedFiles);
11
- if (await fs.exists('.git')) {
10
+ export default async function (options) {
11
+ options = {
12
+ log: process.env.NODE_ENV !== 'test',
13
+ ...options
14
+ };
15
+ await outputFiles(this.cwd, this.generatedFiles);
16
+ if (await fs.exists(pathLib.join(this.cwd, '.git'))) {
12
17
  var _ref, _commitlintPackageCon;
13
- await execaCommand('husky install');
14
- await execa('husky', ['set', '.husky/commit-msg', `npx ${_ref = (_commitlintPackageCon = commitlintPackageConfig.bin, keys(_commitlintPackageCon)), first(_ref)} --edit "$1"`]);
18
+ await execaCommand('husky install', {
19
+ cwd: this.cwd,
20
+ [options.log ? 'stdio' : 'stderr']: 'inherit'
21
+ });
22
+ await execa('husky', ['set', '.husky/commit-msg', `npx ${_ref = (_commitlintPackageCon = commitlintPackageConfig.bin, keys(_commitlintPackageCon)), first(_ref)} --edit "$1"`], {
23
+ cwd: this.cwd,
24
+ [options.log ? 'stdio' : 'stderr']: 'inherit'
25
+ });
15
26
  }
16
- await this.config.prepare();
27
+ await this.config.prepare(options);
17
28
  }
@@ -7,12 +7,14 @@ import fs from 'fs-extra';
7
7
  export default async function (options) {
8
8
  var _ref, _this$packageConfig$n, _ref2, _ref3;
9
9
  options = {
10
- log: true,
10
+ log: process.env.NODE_ENV !== 'test',
11
11
  patterns: [],
12
12
  ...options
13
13
  };
14
14
  const volumeName = (_ref = (_this$packageConfig$n = this.packageConfig.name, replace('@', '')(_this$packageConfig$n)), replace('/', '-')(_ref));
15
- const envSchemaPath = findUpSync('.env.schema.json');
15
+ const envSchemaPath = findUpSync('.env.schema.json', {
16
+ cwd: this.cwd
17
+ });
16
18
  const envVariableNames = (_ref2 = (_ref3 = envSchemaPath ? await fs.readJson(envSchemaPath) : {}, keys(_ref3)), map(name => {
17
19
  var _name;
18
20
  return `TEST_${_name = name, constantCase(_name)}`;
@@ -20,12 +22,13 @@ export default async function (options) {
20
22
  const userInfo = os.userInfo();
21
23
  try {
22
24
  var _ref4, _envVariableNames, _ref5;
23
- return await execa('docker', ['run', '--rm', ...(_ref4 = (_envVariableNames = envVariableNames, filter(name => process.env[name] !== undefined)(_envVariableNames)), flatMap(name => ['--env', `${name}=${process.env[name]}`])(_ref4)), '-v', `${process.cwd()}:/app`, '-v', `${volumeName}:/app/node_modules`, 'dworddesign/testing:latest', 'bash', '-c', (_ref5 = ['pnpm install --frozen-lockfile', '&&', 'pnpm test:raw', ...(options.updateSnapshots ? [' --update-snapshots'] : []), ...options.patterns.map(pattern => `"${pattern}"`), ...(options.grep ? [`-g "${options.grep}"`] : [])], join(' ')(_ref5))], options.log ? {
24
- stdio: 'inherit'
25
- } : {
26
- all: true
25
+ return await execa('docker', ['run', '--rm', ...(_ref4 = (_envVariableNames = envVariableNames, filter(name => process.env[name] !== undefined)(_envVariableNames)), flatMap(name => ['--env', `${name}=${process.env[name]}`])(_ref4)), '-v', `${this.cwd}:/app`, '-v', `${volumeName}:/app/node_modules`, 'dworddesign/testing:latest', 'bash', '-c', (_ref5 = ['pnpm install --frozen-lockfile', '&&', 'pnpm test:raw', ...(options.updateSnapshots ? [' --update-snapshots'] : []), ...options.patterns.map(pattern => `"${pattern}"`), ...(options.grep ? [`-g "${options.grep}"`] : [])], join(' ')(_ref5))], {
26
+ cwd: this.cwd,
27
+ [options.log ? 'stdio' : 'stderr']: 'inherit'
27
28
  });
28
29
  } finally {
29
- await execa('docker', ['run', '--rm', '--tty', '-v', `${process.cwd()}:/app`, '-v', `${volumeName}:/app/node_modules`, 'dworddesign/testing:latest', 'bash', '-c', `chown -R ${userInfo.uid}:${userInfo.gid} /app`]);
30
+ await execa('docker', ['run', '--rm', '--tty', '-v', `${this.cwd}:/app`, '-v', `${volumeName}:/app/node_modules`, 'dworddesign/testing:latest', 'bash', '-c', `chown -R ${userInfo.uid}:${userInfo.gid} /app`], {
31
+ cwd: this.cwd
32
+ });
30
33
  }
31
34
  }
@@ -15,8 +15,10 @@ const validatePackageJson = ajv.compile(packageJsonSchema);
15
15
  export default async function (options) {
16
16
  var _ref;
17
17
  options = {
18
+ all: false,
18
19
  log: process.env.NODE_ENV !== 'test',
19
20
  patterns: [],
21
+ stderr: null,
20
22
  ...options
21
23
  };
22
24
  if (options.patterns.length === 0) {
@@ -26,16 +28,21 @@ export default async function (options) {
26
28
  ${ajv.errorsText(validatePackageJson.errors)}
27
29
  `);
28
30
  }
29
- await this.lint();
30
- await this.depcheck();
31
+ await this.lint(options);
32
+ await this.depcheck(options);
31
33
  }
32
- const runDockerTests = !isCI() || !(_ref = ['win32', 'darwin'], includes(process.platform)(_ref));
33
- return execa(this.packageConfig.type === 'module' ? packageName`c8` : packageName`nyc`, [...(this.packageConfig.type === 'module' ? ['--exclude', 'eslint.config.js'] : []), ...(this.config.testRunner === 'playwright' ? ['playwright', 'test', '--pass-with-no-tests', ...(runDockerTests ? [] : ['--grep-invert', '@usesdocker']), ...(options.updateSnapshots ? ['--update-snapshots'] : []), ...(options.ui ? ['--ui'] : []), ...(options.uiHost ? ['--ui-host', options.uiHost] : []), ...(options.grep ? ['--grep', options.grep] : []), '--trace', 'retain-on-failure', ...(isCI() ? ['--forbid-only'] : []),
34
+ const runDockerTests = !isCI({
35
+ cwd: this.cwd
36
+ }) || !(_ref = ['win32', 'darwin'], includes(process.platform)(_ref));
37
+ return execa(this.packageConfig.type === 'module' ? packageName`c8` : packageName`nyc`, [...(this.packageConfig.type === 'module' ? ['--exclude', 'eslint.config.js'] : []), ...(this.config.testRunner === 'playwright' ? ['playwright', 'test', '--pass-with-no-tests', ...(runDockerTests ? [] : ['--grep-invert', '@usesdocker']), ...(options.updateSnapshots ? ['--update-snapshots'] : []), ...(options.ui ? ['--ui'] : []), ...(options.uiHost ? ['--ui-host', options.uiHost] : []), ...(options.grep ? ['--grep', options.grep] : []), '--trace', 'retain-on-failure', ...(isCI({
38
+ cwd: this.cwd
39
+ }) ? ['--forbid-only'] : []),
34
40
  /**
35
41
  * Reporter set to dot in CI environments by default.
36
42
  * See https://github.com/microsoft/playwright/blob/42ade54975f6990c41cddc7b6e11c46a36648d0d/packages/playwright/src/common/config.ts#L301.
37
43
  */
38
- '--reporter', 'list', ...options.patterns] : ['--reporter', 'lcov', '--reporter', 'text', '--cwd', process.cwd(), '--all', '--exclude', '**/*.spec.js', '--exclude', 'coverage', '--exclude', 'tmp-*', '--exclude', 'dist', 'mocha', '--reporter', _require.resolve(packageName`mocha-spec-reporter-with-file-names`), '--ui', packageName`mocha-ui-exports-auto-describe`, '--require', packageName`@dword-design/pretest`, ...((await fs.exists(P.join('global-test-hooks.js'))) ? ['--require', 'global-test-hooks.js'] : []), '--file', _require.resolve(packageName`@dword-design/setup-test`), ...(runDockerTests ? [] : ['--ignore', '**/*.usesdocker.spec.js']), '--timeout', 130_000, ...(options.patterns.length > 0 ? options.patterns : ['{,!(node_modules)/**/}*.spec.js']), ...(options.grep ? ['--grep', options.grep] : []), ...(process.platform === 'win32' ? ['--exit'] : [])])], {
44
+ '--reporter', 'list', ...options.patterns] : ['--reporter', 'lcov', '--reporter', 'text', '--cwd', this.cwd, '--all', '--exclude', '**/*.spec.js', '--exclude', 'coverage', '--exclude', 'tmp-*', '--exclude', 'dist', 'mocha', '--reporter', _require.resolve(packageName`mocha-spec-reporter-with-file-names`), '--ui', packageName`mocha-ui-exports-auto-describe`, '--require', packageName`@dword-design/pretest`, ...((await fs.exists(P.join(this.cwd, 'global-test-hooks.js'))) ? ['--require', 'global-test-hooks.js'] : []), '--file', _require.resolve(packageName`@dword-design/setup-test`), ...(runDockerTests ? [] : ['--ignore', '**/*.usesdocker.spec.js']), '--timeout', 130_000, ...(options.patterns.length > 0 ? options.patterns : ['{,!(node_modules)/**/}*.spec.js']), ...(options.grep ? ['--grep', options.grep] : []), ...(process.platform === 'win32' ? ['--exit'] : [])])], {
45
+ cwd: this.cwd,
39
46
  env: {
40
47
  NODE_ENV: 'test',
41
48
  ...(this.packageConfig.type === 'module' && {
@@ -47,10 +54,9 @@ export default async function (options) {
47
54
  SNAPSHOT_UPDATE: 1
48
55
  } : {})
49
56
  },
50
- ...(options.log ? {
51
- stdio: 'inherit'
52
- } : {
53
- all: true
57
+ [options.log ? 'stdio' : 'stderr']: 'inherit',
58
+ ...(options.stderr && {
59
+ stderr: options.stderr
54
60
  })
55
61
  });
56
62
  }
@@ -1,7 +1,11 @@
1
1
  import { execaCommandSync } from 'execa';
2
- export default () => {
2
+ export default ({
3
+ cwd = '.'
4
+ } = {}) => {
3
5
  try {
4
- execaCommandSync('is-ci');
6
+ execaCommandSync('is-ci', {
7
+ cwd
8
+ });
5
9
  return true;
6
10
  } catch {
7
11
  return false;
@@ -2,7 +2,7 @@ import jobMatrixStrategy from "./strategies/job-matrix.js";
2
2
  import simpleStrategy from "./strategies/simple.js";
3
3
  export default function () {
4
4
  return {
5
- jobs: (this.config.useJobMatrix && !this.config.testInContainer ? jobMatrixStrategy : simpleStrategy)(this.config),
5
+ jobs: (this.config.useJobMatrix && !this.config.testInContainer ? jobMatrixStrategy : simpleStrategy).call(this),
6
6
  name: 'build',
7
7
  on: {
8
8
  pull_request: {},
@@ -2,7 +2,7 @@ import { map } from '@dword-design/functions';
2
2
  import packageName from 'depcheck-package-name';
3
3
  import parsePackagejsonName from 'parse-packagejson-name';
4
4
  const ci = `dw-${parsePackagejsonName(packageName`@dword-design/ci`).fullName}`;
5
- export default config => {
5
+ export default function () {
6
6
  var _ref;
7
7
  return [{
8
8
  env: {
@@ -11,13 +11,13 @@ export default config => {
11
11
  },
12
12
  name: 'Push changed files',
13
13
  run: `pnpm ${ci} push-changed-files`
14
- }, ...(_ref = [...config.preDeploySteps, {
14
+ }, ...(_ref = [...this.config.preDeploySteps, {
15
15
  env: {
16
16
  GITHUB_TOKEN: '${{ secrets.GITHUB_TOKEN }}',
17
- ...(config.npmPublish ? {
17
+ ...(this.config.npmPublish ? {
18
18
  NPM_TOKEN: '${{ secrets.NPM_TOKEN }}'
19
19
  } : {}),
20
- ...config.deployEnv
20
+ ...this.config.deployEnv
21
21
  },
22
22
  name: 'Release',
23
23
  run: 'pnpm semantic-release'
@@ -25,4 +25,4 @@ export default config => {
25
25
  if: "github.ref == 'refs/heads/master'",
26
26
  ...step
27
27
  }))(_ref))];
28
- };
28
+ }
@@ -1,18 +1,20 @@
1
- import P from 'node:path';
1
+ import pathLib from 'node:path';
2
2
  import { endent, fromPairs, keys, map } from '@dword-design/functions';
3
3
  import { constantCase } from 'change-case';
4
4
  import { findUpStop, findUpSync } from 'find-up';
5
5
  import fs from 'fs-extra';
6
6
  import gitHubAction from 'tagged-template-noop';
7
- export default () => {
7
+ export default function () {
8
8
  var _ref, _ref2, _ref3, _envVariableNames;
9
9
  const envSchemaPath = findUpSync(path => {
10
- if (fs.existsSync('.env.schema.json')) {
10
+ if (fs.existsSync(pathLib.join(path, '.env.schema.json'))) {
11
11
  return '.env.schema.json';
12
12
  }
13
- if (fs.existsSync(P.join(path, 'package.json'))) {
13
+ if (fs.existsSync(pathLib.join(path, 'package.json'))) {
14
14
  return findUpStop;
15
15
  }
16
+ }, {
17
+ cwd: this.cwd
16
18
  });
17
19
  const envVariableNames = (_ref = (_ref2 = envSchemaPath ? fs.readJsonSync(envSchemaPath) : {}, keys(_ref2)), map(name => {
18
20
  var _name;
@@ -36,4 +38,4 @@ export default () => {
36
38
  `
37
39
  }
38
40
  }];
39
- };
41
+ }
@@ -5,7 +5,7 @@ import checkUnknownFilesSteps from "../steps/check-unknown-files.js";
5
5
  import coverageSteps from "../steps/coverage.js";
6
6
  import getReleaseSteps from "../steps/get-release.js";
7
7
  import getTestSteps from "../steps/get-test.js";
8
- export default config => {
8
+ export default function () {
9
9
  var _coverageSteps;
10
10
  return {
11
11
  'cancel-existing': {
@@ -25,7 +25,7 @@ export default config => {
25
25
  }, {
26
26
  uses: gitHubAction`actions/setup-node@v4`,
27
27
  with: {
28
- 'node-version': config.nodeVersion
28
+ 'node-version': this.config.nodeVersion
29
29
  }
30
30
  }, {
31
31
  run: 'corepack enable'
@@ -37,7 +37,7 @@ export default config => {
37
37
  run: 'pnpm install --frozen-lockfile'
38
38
  }, ...checkUnknownFilesSteps, {
39
39
  run: 'pnpm lint'
40
- }, ...getReleaseSteps(config)]
40
+ }, ...getReleaseSteps.call(this)]
41
41
  },
42
42
  test: {
43
43
  needs: 'cancel-existing',
@@ -58,24 +58,24 @@ export default config => {
58
58
  run: 'corepack enable'
59
59
  }, {
60
60
  run: 'pnpm install --frozen-lockfile'
61
- }, ...getTestSteps(), ...(_coverageSteps = coverageSteps, map(step => ({
62
- if: `matrix.os == 'ubuntu-latest' && matrix.node == ${config.nodeVersion}`,
61
+ }, ...getTestSteps.call(this), ...(_coverageSteps = coverageSteps, map(step => ({
62
+ if: `matrix.os == 'ubuntu-latest' && matrix.node == ${this.config.nodeVersion}`,
63
63
  ...step
64
64
  }))(_coverageSteps))],
65
65
  strategy: {
66
66
  matrix: {
67
- include: [...config.supportedNodeVersions.map(version => ({
67
+ include: [...this.config.supportedNodeVersions.map(version => ({
68
68
  node: version,
69
69
  os: 'ubuntu-latest'
70
- })), ...(config.macos ? [{
71
- node: config.nodeVersion,
70
+ })), ...(this.config.macos ? [{
71
+ node: this.config.nodeVersion,
72
72
  os: 'macos-latest'
73
- }] : []), ...(config.windows ? [{
74
- node: config.nodeVersion,
73
+ }] : []), ...(this.config.windows ? [{
74
+ node: this.config.nodeVersion,
75
75
  os: 'windows-latest'
76
76
  }] : [])]
77
77
  }
78
78
  }
79
79
  }
80
80
  };
81
- };
81
+ }
@@ -4,31 +4,33 @@ import checkUnknownFilesSteps from "../steps/check-unknown-files.js";
4
4
  import coverageSteps from "../steps/coverage.js";
5
5
  import getReleaseSteps from "../steps/get-release.js";
6
6
  import getTestSteps from "../steps/get-test.js";
7
- export default config => ({
8
- build: {
9
- if: "!contains(github.event.head_commit.message, '[skip ci]')",
10
- 'runs-on': 'ubuntu-latest',
11
- steps: [...cancelExistingSteps, {
12
- uses: gitHubAction`actions/checkout@v4`,
13
- with: {
14
- 'fetch-depth': 0,
15
- lfs: true,
16
- ref: "${{ github.event.pull_request.head.repo.full_name == github.repository && github.event.pull_request.head.ref || '' }}"
17
- }
18
- }, {
19
- uses: gitHubAction`actions/setup-node@v4`,
20
- with: {
21
- 'check-latest': true,
22
- 'node-version': config.nodeVersion
23
- }
24
- }, {
25
- run: 'corepack enable'
26
- }, {
27
- run: 'git config --global user.email "actions@github.com"'
28
- }, {
29
- run: 'git config --global user.name "GitHub Actions"'
30
- }, {
31
- run: 'pnpm install --frozen-lockfile'
32
- }, ...getTestSteps(), ...coverageSteps, ...checkUnknownFilesSteps, ...getReleaseSteps(config)]
33
- }
34
- });
7
+ export default function () {
8
+ return {
9
+ build: {
10
+ if: "!contains(github.event.head_commit.message, '[skip ci]')",
11
+ 'runs-on': 'ubuntu-latest',
12
+ steps: [...cancelExistingSteps, {
13
+ uses: gitHubAction`actions/checkout@v4`,
14
+ with: {
15
+ 'fetch-depth': 0,
16
+ lfs: true,
17
+ ref: "${{ github.event.pull_request.head.repo.full_name == github.repository && github.event.pull_request.head.ref || '' }}"
18
+ }
19
+ }, {
20
+ uses: gitHubAction`actions/setup-node@v4`,
21
+ with: {
22
+ 'check-latest': true,
23
+ 'node-version': this.config.nodeVersion
24
+ }
25
+ }, {
26
+ run: 'corepack enable'
27
+ }, {
28
+ run: 'git config --global user.email "actions@github.com"'
29
+ }, {
30
+ run: 'git config --global user.name "GitHub Actions"'
31
+ }, {
32
+ run: 'pnpm install --frozen-lockfile'
33
+ }, ...getTestSteps.call(this), ...coverageSteps, ...checkUnknownFilesSteps, ...getReleaseSteps.call(this)]
34
+ }
35
+ };
36
+ }
@@ -1,3 +1,4 @@
1
+ import pathLib from 'node:path';
1
2
  import { keys, mapValues, pick, stubTrue } from '@dword-design/functions';
2
3
  import packageName from 'depcheck-package-name';
3
4
  import fs from 'fs-extra';
@@ -49,7 +50,7 @@ export default function () {
49
50
  engines: {
50
51
  node: `>=${this.config.minNodeVersion || this.config.supportedNodeVersions[0]}`
51
52
  },
52
- files: ['dist', ...(fs.existsSync('types.d.ts') ? ['types.d.ts'] : [])],
53
+ files: ['dist', ...(fs.existsSync(pathLib.join(this.cwd, 'types.d.ts')) ? ['types.d.ts'] : [])],
53
54
  license: 'MIT',
54
55
  ...this.config.packageConfig,
55
56
  scripts: (_ref = (_commandNames = commandNames, mapValues((handler, name) => this.packageConfig.name === '@dword-design/base' ? `rimraf dist && babel --config-file ${packageName`@dword-design/babel-config`} --copy-files --no-copy-ignored --out-dir dist --ignore "**/*.spec.js" src && node dist/cli.js ${name}` : `base ${name}`)(_commandNames)), sortKeys(_ref))
@@ -1,11 +1,16 @@
1
+ import pathLib from 'node:path';
1
2
  import fs from 'fs-extra';
2
3
  import hostedGitInfo from 'hosted-git-info';
3
4
  import parseGitConfig from 'parse-git-config';
4
- export default () => {
5
- if (!fs.existsSync('.git')) {
5
+ export default ({
6
+ cwd = '.'
7
+ } = {}) => {
8
+ if (!fs.existsSync(pathLib.join(cwd, '.git'))) {
6
9
  return;
7
10
  }
8
- const gitUrl = parseGitConfig.sync()['remote "origin"']?.url;
11
+ const gitUrl = parseGitConfig.sync({
12
+ cwd
13
+ })['remote "origin"']?.url;
9
14
  if (gitUrl === undefined) {
10
15
  return;
11
16
  }
package/dist/index.js CHANGED
@@ -1,4 +1,4 @@
1
- import P from 'node:path';
1
+ import pathLib from 'node:path';
2
2
  import { endent, identity, mapValues } from '@dword-design/functions';
3
3
  import jitiBabelTransform from '@dword-design/jiti-babel-transform';
4
4
  import deepmerge from 'deepmerge';
@@ -6,11 +6,10 @@ import depcheck from 'depcheck';
6
6
  import depcheckDetectorBinName from 'depcheck-detector-bin-name';
7
7
  import depcheckDetectorExeca from 'depcheck-detector-execa';
8
8
  import depcheckDetectorPackageName from 'depcheck-detector-package-name';
9
- import depcheckDetectorTinyexec from 'depcheck-detector-tinyexec';
10
9
  import packageName from 'depcheck-package-name';
11
10
  import depcheckParserBabel from 'depcheck-parser-babel';
12
11
  import fs from 'fs-extra';
13
- import { createJiti } from 'jiti';
12
+ import jiti from 'jiti';
14
13
  import { transform as pluginNameToPackageName } from 'plugin-name-to-package-name';
15
14
  import checkUnknownFiles from "./commands/check-unknown-files/index.js";
16
15
  import commit from "./commands/commit/index.js";
@@ -44,10 +43,14 @@ const mergeConfigs = (...configs) => {
44
43
  return result;
45
44
  };
46
45
  class Base {
47
- constructor(config = null) {
46
+ constructor(config = null, {
47
+ cwd = '.'
48
+ } = {}) {
48
49
  var _this$config$commands;
49
- const jitiInstance = createJiti(process.cwd(), {
50
- moduleCache: false,
50
+ this.cwd = cwd;
51
+ const jitiInstance = jiti(pathLib.resolve(this.cwd), {
52
+ esmResolve: true,
53
+ interopDefault: true,
51
54
  transform: jitiBabelTransform
52
55
  });
53
56
  if (config === null) {
@@ -61,12 +64,12 @@ class Base {
61
64
  if (config.name) {
62
65
  config.name = pluginNameToPackageName(config.name, 'base-config');
63
66
  }
64
- this.packageConfig = fs.existsSync('package.json') ? fs.readJsonSync('package.json') : {};
67
+ this.packageConfig = fs.existsSync(pathLib.join(this.cwd, 'package.json')) ? fs.readJsonSync(pathLib.join(this.cwd, 'package.json')) : {};
65
68
  const defaultConfig = {
66
69
  allowedMatches: [],
67
70
  commands: {},
68
71
  depcheckConfig: {
69
- detectors: [depcheck.detector.importDeclaration, depcheck.detector.requireCallExpression, depcheck.detector.requireResolveCallExpression, depcheckDetectorExeca, depcheckDetectorTinyexec, depcheckDetectorPackageName, depcheckDetectorBinName],
72
+ detectors: [depcheck.detector.importDeclaration, depcheck.detector.requireCallExpression, depcheck.detector.requireResolveCallExpression, depcheckDetectorExeca, depcheckDetectorPackageName, depcheckDetectorBinName],
70
73
  ignorePath: '.gitignore',
71
74
  parsers: {
72
75
  '**/*.js': depcheckParserBabel
@@ -77,7 +80,9 @@ class Base {
77
80
  deployEnv: {},
78
81
  deployPlugins: [],
79
82
  editorIgnore: [],
80
- git: getGitInfo(),
83
+ git: getGitInfo({
84
+ cwd: this.cwd
85
+ }),
81
86
  gitignore: [],
82
87
  lint: identity,
83
88
  macos: true,
@@ -104,13 +109,8 @@ class Base {
104
109
  };
105
110
  const configsToMerge = [defaultConfig];
106
111
  if (config.name) {
107
- const inheritedConfigPath = config.name === this.packageConfig.name ? P.resolve('src', 'index.js') : config.name;
112
+ const inheritedConfigPath = config.name === this.packageConfig.name ? pathLib.resolve(this.cwd, 'src', 'index.js') : config.name;
108
113
  let inheritedConfig = inheritedConfigPath ? jitiInstance(inheritedConfigPath) : undefined;
109
-
110
- // I don't know why Jiti doesn't interopDefault here
111
- if (inheritedConfig?.default) {
112
- inheritedConfig = inheritedConfig.default;
113
- }
114
114
  if (typeof inheritedConfig === 'function') {
115
115
  inheritedConfig = inheritedConfig(mergeConfigs(defaultConfig, config));
116
116
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dword-design/base",
3
- "version": "12.0.14",
3
+ "version": "12.0.16",
4
4
  "description": "Base package for projects.",
5
5
  "repository": "dword-design/base",
6
6
  "funding": "https://github.com/sponsors/dword-design",
@@ -50,7 +50,6 @@
50
50
  "depcheck-detector-bin-name": "^1.0.2",
51
51
  "depcheck-detector-execa": "^4.0.0",
52
52
  "depcheck-detector-package-name": "^3.0.4",
53
- "depcheck-detector-tinyexec": "^1.0.0",
54
53
  "depcheck-package-name": "^3.0.1",
55
54
  "depcheck-parser-babel": "^3.0.57",
56
55
  "eslint": "^9.27.0",
@@ -63,7 +62,7 @@
63
62
  "husky": "^8.0.3",
64
63
  "ignore": "^5.3.2",
65
64
  "is-ci": "^3.0.1",
66
- "jiti": "^2.4.2",
65
+ "jiti": "^1.21.7",
67
66
  "make-cli": "^4.0.0",
68
67
  "mocha": "^10.8.2",
69
68
  "mocha-spec-reporter-with-file-names": "npm:@dword-design/mocha-spec-reporter-with-file-names@^0.0.1",