sku 12.4.4 → 12.4.6

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.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,17 @@
1
1
  # sku
2
2
 
3
+ ## 12.4.6
4
+
5
+ ### Patch Changes
6
+
7
+ - Fix package manager detection in non-monorepos ([#907](https://github.com/seek-oss/sku/pull/907))
8
+
9
+ ## 12.4.5
10
+
11
+ ### Patch Changes
12
+
13
+ - Bump some dependencies ([#904](https://github.com/seek-oss/sku/pull/904))
14
+
3
15
  ## 12.4.4
4
16
 
5
17
  ### Patch Changes
@@ -2,16 +2,18 @@ const { isYarn } = require('../../lib/packageManager');
2
2
  const { lintExtensions } = require('../../lib/lint');
3
3
  const { getCommand } = require('@antfu/ni');
4
4
 
5
- const steps = {};
5
+ /**
6
+ * @type {import('lint-staged').Config}
7
+ */
8
+ const config = {
9
+ [`**/*.{${lintExtensions},md,less}`]: ['sku format', 'sku lint'],
10
+ };
6
11
 
7
12
  // Yarn lock integrity check
8
13
  if (isYarn) {
9
- steps['+(package.json|yarn.lock)'] = [
10
- () => getCommand('yarn', 'install', ['--check-files']),
14
+ config['+(package.json|yarn.lock)'] = [
15
+ getCommand('yarn', 'install', ['--check-files']),
11
16
  ];
12
17
  }
13
18
 
14
- // Format & lint
15
- steps[`**/*.{${lintExtensions},md,less}`] = ['sku format', 'sku lint'];
16
-
17
- module.exports = steps;
19
+ module.exports = config;
@@ -1,6 +1,8 @@
1
+ const { existsSync } = require('node:fs');
2
+ const { join } = require('node:path');
1
3
  const { cwd } = require('../lib/cwd');
2
4
  const { findRootSync } = require('@manypkg/find-root');
3
- const { getCommand, INSTALL_PAGE } = require('@antfu/ni');
5
+ const { getCommand, INSTALL_PAGE, LOCKS } = require('@antfu/ni');
4
6
 
5
7
  const { sync: which } = require('which');
6
8
  const skuArgs = require('../config/args');
@@ -10,6 +12,19 @@ const skuArgs = require('../config/args');
10
12
  /** @type {Array<SupportedPackageManager>} */
11
13
  const supportedPackageManagers = ['yarn', 'pnpm', 'npm'];
12
14
 
15
+ /** @type {Record<SupportedPackageManager, string>} */
16
+ const lockfileForPackageManager = Object.fromEntries(
17
+ Object.entries(LOCKS)
18
+ .filter(([, packageManager]) =>
19
+ supportedPackageManagers.includes(packageManager),
20
+ )
21
+ .map(([lockfileName, packageManager]) => [packageManager, lockfileName]),
22
+ );
23
+
24
+ const supportedLockfiles = supportedPackageManagers.map(
25
+ (packageManager) => lockfileForPackageManager[packageManager],
26
+ );
27
+
13
28
  /**
14
29
  * @param {SupportedPackageManager} commandName
15
30
  * @returns {SupportedPackageManager | null}
@@ -24,18 +39,28 @@ const detectPackageManager = () =>
24
39
 
25
40
  /**
26
41
  * Get the package manager and root directory of the project. If the project does not have a
27
- * project manager configured, a supported package manager will be detected in your `PATH`, and
42
+ * package manager configured, a supported package manager will be detected in your `PATH`, and
28
43
  * `rootDir` will be `null`.
29
44
  * @returns {{packageManager: SupportedPackageManager, rootDir: string | null}}
30
45
  */
31
46
  const getPackageManager = () => {
32
47
  let _packageManager = skuArgs?.packageManager;
33
48
 
49
+ // @manypkg/find-root only returns a tool if it finds a monorepo.
50
+ // If it finds a regular repo, it will return a 'root' tool, which is absolutely useless.
51
+ // So we need to detect the package manager ourselves. I'd use `detect` from from `@antfu/ni` or
52
+ // `detect-package-manager`, but they're async only and we can't make getPackageManager async.
34
53
  try {
35
- const {
36
- tool: { type: foundPackageManager },
37
- rootDir,
38
- } = findRootSync(cwd());
54
+ const { rootDir } = findRootSync(cwd());
55
+
56
+ let foundPackageManager;
57
+
58
+ for (const supportedLockfile of supportedLockfiles) {
59
+ if (existsSync(join(rootDir, supportedLockfile))) {
60
+ foundPackageManager = LOCKS[supportedLockfile];
61
+ break;
62
+ }
63
+ }
39
64
 
40
65
  if (!supportedPackageManagers.includes(foundPackageManager)) {
41
66
  throw new Error('Unsupported package manager found');
@@ -126,7 +151,7 @@ const getAddCommand = ({ type, logLevel, deps, exact }) => {
126
151
  return getCommand(packageManager, 'add', args);
127
152
  };
128
153
 
129
- const getInstallCommand = () => getCommand(packageManager, 'install', []);
154
+ const getInstallCommand = () => getCommand(packageManager, 'install');
130
155
 
131
156
  const getWhyCommand = () => {
132
157
  const whyCommand = isPnpm ? 'why -r' : 'why';
package/lib/preCommit.js CHANGED
@@ -1,11 +1,12 @@
1
1
  const chalk = require('chalk');
2
+
3
+ const config = require('../config/lintStaged/lintStagedConfig');
2
4
  const lintStaged = require('lint-staged');
3
- const configPath = require.resolve('../config/lintStaged/lintStagedConfig');
4
5
 
5
6
  module.exports = async () => {
6
7
  let success = false;
7
8
  try {
8
- success = await lintStaged({ configPath });
9
+ success = await lintStaged({ config });
9
10
  } catch (e) {
10
11
  console.error(chalk.red(e));
11
12
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "sku",
3
- "version": "12.4.4",
3
+ "version": "12.4.6",
4
4
  "description": "Front-end development toolkit, powered by Webpack, Babel, CSS Modules, Less and Jest",
5
5
  "main": "index.js",
6
6
  "bin": {
@@ -71,13 +71,13 @@
71
71
  "cssnano": "^6.0.0",
72
72
  "death": "^1.1.0",
73
73
  "debug": "^4.3.1",
74
- "dedent": "^0.7.0",
75
- "didyoumean2": "^5.0.0",
74
+ "dedent": "^1.5.1",
75
+ "didyoumean2": "^6.0.1",
76
76
  "ejs": "^3.1.8",
77
77
  "empty-dir": "^3.0.0",
78
78
  "ensure-gitignore": "^1.1.2",
79
79
  "env-ci": "^7.0.0",
80
- "esbuild": "^0.17.0",
80
+ "esbuild": "^0.19.7",
81
81
  "esbuild-register": "^3.3.3",
82
82
  "escape-string-regexp": "^4.0.0",
83
83
  "eslint": "^8.41.0",
@@ -128,7 +128,6 @@
128
128
  },
129
129
  "devDependencies": {
130
130
  "@types/cross-spawn": "^6.0.3",
131
- "@types/dedent": "^0.7.0",
132
131
  "@types/express": "^4.17.11",
133
132
  "@types/react": "^18.2.3",
134
133
  "@types/react-dom": "^18.2.3",