diff --git a/README.md b/README.md index f0e4254..8445262 100644 --- a/README.md +++ b/README.md @@ -40,7 +40,7 @@ $packagerName = $detectedPackager->getName(); $detector = new Runtime( $files, new Strategy(Strategy::FILEMATCH), // similar for LANGUAGES and EXTENSIONS - 'npm' + 'pnpm' ); $detector @@ -62,7 +62,7 @@ $runtimeCommands = $detectedRuntime->getCommands(); // Initialise Framework Detection $files = ['src', 'types', 'makefile', 'components.js', 'debug.js', 'package.json', 'svelte.config.js']; -$packager = 'npm'; +$packager = 'pnpm'; $detector = new Framework($files, $packager); $detector @@ -173,4 +173,4 @@ composer test ## Copyright and license -The MIT License (MIT) [http://www.opensource.org/licenses/mit-license.php](http://www.opensource.org/licenses/mit-license.php) \ No newline at end of file +The MIT License (MIT) [http://www.opensource.org/licenses/mit-license.php](http://www.opensource.org/licenses/mit-license.php) diff --git a/docs/add-new-adapter.md b/docs/add-new-adapter.md index c5d97fc..5adf2a3 100644 --- a/docs/add-new-adapter.md +++ b/docs/add-new-adapter.md @@ -193,12 +193,12 @@ class MyFramework extends Framework public function getInstallCommand(): string { - return 'npm install'; + return 'pnpm install'; } public function getBuildCommand(): string { - return 'npm run build'; + return 'pnpm run build'; } public function getOutputDirectory(): string @@ -212,4 +212,4 @@ Only include dependencies strictly necessary for the adapter, preferably officia ### Testing with Docker 🛠️ -The existing test suite is helpful when developing a new Detector/ Detection adapter. Use official Docker images from trusted sources. Add new tests for your new Detector/ Detection adapter in `tests/unit/DetectorTest.php` test class. The specific `docker-compose` command for testing can be found in the [README](/README.md#tests). \ No newline at end of file +The existing test suite is helpful when developing a new Detector/ Detection adapter. Use official Docker images from trusted sources. Add new tests for your new Detector/ Detection adapter in `tests/unit/DetectorTest.php` test class. The specific `docker-compose` command for testing can be found in the [README](/README.md#tests). diff --git a/src/Detection/Framework/Analog.php b/src/Detection/Framework/Analog.php index 31f824a..10cf610 100644 --- a/src/Detection/Framework/Analog.php +++ b/src/Detection/Framework/Analog.php @@ -30,7 +30,8 @@ public function getInstallCommand(): string return match ($this->packager) { 'yarn' => 'yarn install', 'pnpm' => 'pnpm install', - default => 'npm install', + 'npm' => 'npm install', + default => 'pnpm install', }; } @@ -38,8 +39,9 @@ public function getBuildCommand(): string { return match ($this->packager) { 'yarn' => 'yarn build', - 'pnpm' => 'pnpm build', - default => 'npm run build', + 'pnpm' => 'pnpm run build', + 'npm' => 'npm run build', + default => 'pnpm run build', }; } diff --git a/src/Detection/Framework/Angular.php b/src/Detection/Framework/Angular.php index e676885..91510fe 100644 --- a/src/Detection/Framework/Angular.php +++ b/src/Detection/Framework/Angular.php @@ -30,7 +30,8 @@ public function getInstallCommand(): string return match ($this->packager) { 'yarn' => 'yarn install', 'pnpm' => 'pnpm install', - default => 'npm install', + 'npm' => 'npm install', + default => 'pnpm install', }; } @@ -38,8 +39,9 @@ public function getBuildCommand(): string { return match ($this->packager) { 'yarn' => 'yarn build', - 'pnpm' => 'pnpm build', - default => 'npm run build', + 'pnpm' => 'pnpm run build', + 'npm' => 'npm run build', + default => 'pnpm run build', }; } diff --git a/src/Detection/Framework/Astro.php b/src/Detection/Framework/Astro.php index 58a95d1..6db7fe0 100644 --- a/src/Detection/Framework/Astro.php +++ b/src/Detection/Framework/Astro.php @@ -48,7 +48,8 @@ public function getInstallCommand(): string return match ($this->packager) { 'yarn' => 'yarn install', 'pnpm' => 'pnpm install', - default => 'npm install', + 'npm' => 'npm install', + default => 'pnpm install', }; } @@ -56,8 +57,9 @@ public function getBuildCommand(): string { return match ($this->packager) { 'yarn' => 'yarn build', - 'pnpm' => 'pnpm build', - default => 'npm run build', + 'pnpm' => 'pnpm run build', + 'npm' => 'npm run build', + default => 'pnpm run build', }; } diff --git a/src/Detection/Framework/Lynx.php b/src/Detection/Framework/Lynx.php index 376c8cd..d427e19 100644 --- a/src/Detection/Framework/Lynx.php +++ b/src/Detection/Framework/Lynx.php @@ -30,7 +30,8 @@ public function getInstallCommand(): string return match ($this->packager) { 'yarn' => 'yarn install', 'pnpm' => 'pnpm install', - default => 'npm install', + 'npm' => 'npm install', + default => 'pnpm install', }; } @@ -38,8 +39,9 @@ public function getBuildCommand(): string { return match ($this->packager) { 'yarn' => 'yarn build', - 'pnpm' => 'pnpm build', - default => 'npm run build', + 'pnpm' => 'pnpm run build', + 'npm' => 'npm run build', + default => 'pnpm run build', }; } diff --git a/src/Detection/Framework/NextJs.php b/src/Detection/Framework/NextJs.php index 2245844..7b43ec0 100644 --- a/src/Detection/Framework/NextJs.php +++ b/src/Detection/Framework/NextJs.php @@ -30,7 +30,8 @@ public function getInstallCommand(): string return match ($this->packager) { 'yarn' => 'yarn install', 'pnpm' => 'pnpm install', - default => 'npm install', + 'npm' => 'npm install', + default => 'pnpm install', }; } @@ -38,8 +39,9 @@ public function getBuildCommand(): string { return match ($this->packager) { 'yarn' => 'yarn build', - 'pnpm' => 'pnpm build', - default => 'npm run build', + 'pnpm' => 'pnpm run build', + 'npm' => 'npm run build', + default => 'pnpm run build', }; } diff --git a/src/Detection/Framework/Nuxt.php b/src/Detection/Framework/Nuxt.php index 356cd8c..cfd4e8b 100644 --- a/src/Detection/Framework/Nuxt.php +++ b/src/Detection/Framework/Nuxt.php @@ -30,7 +30,8 @@ public function getInstallCommand(): string return match ($this->packager) { 'yarn' => 'yarn install', 'pnpm' => 'pnpm install', - default => 'npm install', + 'npm' => 'npm install', + default => 'pnpm install', }; } @@ -38,8 +39,9 @@ public function getBuildCommand(): string { return match ($this->packager) { 'yarn' => 'yarn build', - 'pnpm' => 'pnpm build', - default => 'npm run build', + 'pnpm' => 'pnpm run build', + 'npm' => 'npm run build', + default => 'pnpm run build', }; } diff --git a/src/Detection/Framework/React.php b/src/Detection/Framework/React.php index 2386e73..7413fd6 100644 --- a/src/Detection/Framework/React.php +++ b/src/Detection/Framework/React.php @@ -30,7 +30,8 @@ public function getInstallCommand(): string return match ($this->packager) { 'yarn' => 'yarn install', 'pnpm' => 'pnpm install', - default => 'npm install', + 'npm' => 'npm install', + default => 'pnpm install', }; } @@ -38,8 +39,9 @@ public function getBuildCommand(): string { return match ($this->packager) { 'yarn' => 'yarn build', - 'pnpm' => 'pnpm build', - default => 'npm run build', + 'pnpm' => 'pnpm run build', + 'npm' => 'npm run build', + default => 'pnpm run build', }; } diff --git a/src/Detection/Framework/ReactNative.php b/src/Detection/Framework/ReactNative.php index 4616079..f5832ef 100644 --- a/src/Detection/Framework/ReactNative.php +++ b/src/Detection/Framework/ReactNative.php @@ -30,7 +30,8 @@ public function getInstallCommand(): string return match ($this->packager) { 'yarn' => 'yarn install', 'pnpm' => 'pnpm install', - default => 'npm install', + 'npm' => 'npm install', + default => 'pnpm install', }; } @@ -38,8 +39,9 @@ public function getBuildCommand(): string { return match ($this->packager) { 'yarn' => 'yarn build', - 'pnpm' => 'pnpm build', - default => 'npm run build', + 'pnpm' => 'pnpm run build', + 'npm' => 'npm run build', + default => 'pnpm run build', }; } diff --git a/src/Detection/Framework/Remix.php b/src/Detection/Framework/Remix.php index 5dee017..6b68c83 100644 --- a/src/Detection/Framework/Remix.php +++ b/src/Detection/Framework/Remix.php @@ -30,7 +30,8 @@ public function getInstallCommand(): string return match ($this->packager) { 'yarn' => 'yarn install', 'pnpm' => 'pnpm install', - default => 'npm install', + 'npm' => 'npm install', + default => 'pnpm install', }; } @@ -38,8 +39,9 @@ public function getBuildCommand(): string { return match ($this->packager) { 'yarn' => 'yarn build', - 'pnpm' => 'pnpm build', - default => 'npm run build', + 'pnpm' => 'pnpm run build', + 'npm' => 'npm run build', + default => 'pnpm run build', }; } diff --git a/src/Detection/Framework/Svelte.php b/src/Detection/Framework/Svelte.php index d509273..9a096da 100644 --- a/src/Detection/Framework/Svelte.php +++ b/src/Detection/Framework/Svelte.php @@ -30,7 +30,8 @@ public function getInstallCommand(): string return match ($this->packager) { 'yarn' => 'yarn install', 'pnpm' => 'pnpm install', - default => 'npm install', + 'npm' => 'npm install', + default => 'pnpm install', }; } @@ -38,8 +39,9 @@ public function getBuildCommand(): string { return match ($this->packager) { 'yarn' => 'yarn build', - 'pnpm' => 'pnpm build', - default => 'npm run build', + 'pnpm' => 'pnpm run build', + 'npm' => 'npm run build', + default => 'pnpm run build', }; } diff --git a/src/Detection/Framework/SvelteKit.php b/src/Detection/Framework/SvelteKit.php index 3a08445..0c35be1 100644 --- a/src/Detection/Framework/SvelteKit.php +++ b/src/Detection/Framework/SvelteKit.php @@ -30,7 +30,8 @@ public function getInstallCommand(): string return match ($this->packager) { 'yarn' => 'yarn install', 'pnpm' => 'pnpm install', - default => 'npm install', + 'npm' => 'npm install', + default => 'pnpm install', }; } @@ -38,8 +39,9 @@ public function getBuildCommand(): string { return match ($this->packager) { 'yarn' => 'yarn build', - 'pnpm' => 'pnpm build', - default => 'npm run build', + 'pnpm' => 'pnpm run build', + 'npm' => 'npm run build', + default => 'pnpm run build', }; } diff --git a/src/Detection/Framework/TanStackStart.php b/src/Detection/Framework/TanStackStart.php index f270766..921c82d 100644 --- a/src/Detection/Framework/TanStackStart.php +++ b/src/Detection/Framework/TanStackStart.php @@ -30,7 +30,8 @@ public function getInstallCommand(): string return match ($this->packager) { 'yarn' => 'yarn install', 'pnpm' => 'pnpm install', - default => 'npm install', + 'npm' => 'npm install', + default => 'pnpm install', }; } @@ -38,8 +39,9 @@ public function getBuildCommand(): string { return match ($this->packager) { 'yarn' => 'yarn build', - 'pnpm' => 'pnpm build', - default => 'npm run build', + 'pnpm' => 'pnpm run build', + 'npm' => 'npm run build', + default => 'pnpm run build', }; } diff --git a/src/Detection/Framework/Vue.php b/src/Detection/Framework/Vue.php index ad29e18..281e616 100644 --- a/src/Detection/Framework/Vue.php +++ b/src/Detection/Framework/Vue.php @@ -30,7 +30,8 @@ public function getInstallCommand(): string return match ($this->packager) { 'yarn' => 'yarn install', 'pnpm' => 'pnpm install', - default => 'npm install', + 'npm' => 'npm install', + default => 'pnpm install', }; } @@ -38,8 +39,9 @@ public function getBuildCommand(): string { return match ($this->packager) { 'yarn' => 'yarn build', - 'pnpm' => 'pnpm build', - default => 'npm run build', + 'pnpm' => 'pnpm run build', + 'npm' => 'npm run build', + default => 'pnpm run build', }; } diff --git a/src/Detection/Packager/PNPM.php b/src/Detection/Packager/PNPM.php index f15ba99..e9691e8 100644 --- a/src/Detection/Packager/PNPM.php +++ b/src/Detection/Packager/PNPM.php @@ -16,6 +16,8 @@ public function getName(): string */ public function getFiles(): array { - return ['pnpm-lock.yaml']; + return [ + 'pnpm-lock.yaml', + ]; } } diff --git a/src/Detection/Runtime/Node.php b/src/Detection/Runtime/Node.php index 6477231..0ce6f60 100644 --- a/src/Detection/Runtime/Node.php +++ b/src/Detection/Runtime/Node.php @@ -22,9 +22,10 @@ public function getLanguages(): array public function getCommands(): string { return match ($this->packager) { - 'yarn' => 'yarn install && yarn build', - 'pnpm' => 'pnpm install && pnpm run build', - default => 'npm install && npm run build', + 'yarn' => 'yarn install', + 'pnpm' => 'pnpm install', + 'npm' => 'npm install', + default => 'pnpm install', }; } diff --git a/src/Detector/Framework.php b/src/Detector/Framework.php index 201601c..a3a79e5 100644 --- a/src/Detector/Framework.php +++ b/src/Detector/Framework.php @@ -16,9 +16,9 @@ class Framework extends Detector */ protected array $options = []; - protected string $packager = 'npm'; + protected string $packager = 'pnpm'; - public function __construct(string $packager = 'npm') + public function __construct(string $packager = 'pnpm') { parent::__construct(); $this->packager = $packager; diff --git a/src/Detector/Runtime.php b/src/Detector/Runtime.php index 735ebb8..d4441f7 100644 --- a/src/Detector/Runtime.php +++ b/src/Detector/Runtime.php @@ -14,9 +14,9 @@ class Runtime extends Detector protected Strategy $strategy; - protected string $packager = 'npm'; + protected string $packager = 'pnpm'; - public function __construct(Strategy $strategy, string $packager = 'npm') + public function __construct(Strategy $strategy, string $packager = 'pnpm') { parent::__construct(); $this->strategy = $strategy; diff --git a/tests/unit/DetectorTest.php b/tests/unit/DetectorTest.php index 226b9e6..f180a00 100644 --- a/tests/unit/DetectorTest.php +++ b/tests/unit/DetectorTest.php @@ -88,7 +88,7 @@ public function testDetectRuntimeByFilematch( ?string $runtime, ?string $commands, ?string $entrypoint, - string $packager = 'npm' + string $packager = 'pnpm' ): void { $detector = new Runtime( new Strategy(Strategy::FILEMATCH), @@ -130,12 +130,12 @@ public function testDetectRuntimeByFilematch( public function runtimeDataProviderByFilematch(): array { return [ - [['package-lock.json', 'yarn.lock', 'tsconfig.json'], 'node', 'npm install && npm run build', 'index.js', 'npm'], - [['package-lock.json', 'yarn.lock', 'tsconfig.json'], 'node', 'yarn install && yarn build', 'index.js', 'yarn'], - [['composer.json', 'composer.lock'], 'php', 'composer install && composer run build', 'index.php', 'npm'], - [['pubspec.yaml'], 'dart', 'dart pub get', 'main.dart', 'npm'], - [['Gemfile', 'Gemfile.lock'], 'ruby', 'bundle install && bundle exec rake build', 'main.rb', 'npm'], - [['index.html', 'style.css'], null, null, null, 'npm'], // Test for FAILURE + [['package-lock.json', 'yarn.lock', 'tsconfig.json'], 'node', 'pnpm install', 'index.js', 'pnpm'], + [['package-lock.json', 'yarn.lock', 'tsconfig.json'], 'node', 'yarn install', 'index.js', 'yarn'], + [['composer.json', 'composer.lock'], 'php', 'composer install && composer run build', 'index.php', 'pnpm'], + [['pubspec.yaml'], 'dart', 'dart pub get', 'main.dart', 'pnpm'], + [['Gemfile', 'Gemfile.lock'], 'ruby', 'bundle install && bundle exec rake build', 'main.rb', 'pnpm'], + [['index.html', 'style.css'], null, null, null, 'pnpm'], // Test for FAILURE ]; } @@ -147,7 +147,7 @@ public function testDetectRuntimeByLanguage( array $files, ?string $runtime, ?string $commands, - string $packager = 'npm' + string $packager = 'pnpm' ): void { $detector = new Runtime( new Strategy(Strategy::LANGUAGES), @@ -191,13 +191,13 @@ public function runtimeDataProviderByLanguages(): array [ ['TypeScript', 'JavaScript', 'DockerFile'], 'node', - 'npm install && npm run build', - 'npm', + 'pnpm install', + 'pnpm', ], [ ['TypeScript', 'JavaScript', 'DockerFile'], 'node', - 'yarn install && yarn build', + 'yarn install', 'yarn', ], // Test for FAILURE @@ -205,7 +205,7 @@ public function runtimeDataProviderByLanguages(): array ['HTML'], null, null, - 'npm', + 'pnpm', ], ]; } @@ -218,7 +218,7 @@ public function testDetectRuntimeByFileExtension( array $files, ?string $runtime, ?string $commands, - string $packager = 'npm' + string $packager = 'pnpm' ): void { $detector = new Runtime( new Strategy(Strategy::EXTENSION), @@ -259,8 +259,8 @@ public function testDetectRuntimeByFileExtension( public function runtimeDataProviderByFileExtensions(): array { return [ - [['main.ts', 'main.js', 'DockerFile'], 'node', 'npm install && npm run build'], - [['main.ts', 'main.js', 'DockerFile'], 'node', 'yarn install && yarn build', 'yarn'], + [['main.ts', 'main.js', 'DockerFile'], 'node', 'pnpm install'], + [['main.ts', 'main.js', 'DockerFile'], 'node', 'yarn install', 'yarn'], [['composer.json', 'index.php', 'DockerFile'], 'php', 'composer install && composer run build'], [['index.html', 'style.css'], null, null], // Test for FAILURE ]; @@ -270,7 +270,7 @@ public function runtimeDataProviderByFileExtensions(): array * @param string[] $files List of files to check * @dataProvider frameworkDataProvider */ - public function testFrameworkDetection(array $files, ?string $framework, ?string $installCommand = null, ?string $buildCommand = null, ?string $outputDirectory = null, string $packager = 'npm'): void + public function testFrameworkDetection(array $files, ?string $framework, ?string $installCommand = null, ?string $buildCommand = null, ?string $outputDirectory = null, string $packager = 'pnpm'): void { $detector = new Framework($packager); @@ -309,14 +309,14 @@ public function testFrameworkDetection(array $files, ?string $framework, ?string public function frameworkDataProvider(): array { return [ - [['src', 'types', 'makefile', 'components.js', 'debug.js', 'package.json', 'svelte.config.js'], 'sveltekit', 'npm install', 'npm run build', './build'], - [['app', 'backend', 'public', 'Dockerfile', 'docker-compose.yml', 'ecosystem.config.js', 'middleware.ts', 'next.config.js', 'package-lock.json', 'package.json', 'server.js', 'tsconfig.json'], 'nextjs', 'npm install', 'npm run build', './.next'], - [['assets', 'components', 'layouts', 'pages', 'babel.config.js', 'error.vue', 'nuxt.config.js', 'yarn.lock'], 'nuxt', 'npm install', 'npm run build', './output'], - [['lynx.config.js'], 'lynx', 'npm install', 'npm run build', './dist'], - [['src', 'package.json', 'tsconfig.json', 'angular.json', 'logo.png'], 'angular', 'npm install', 'npm run build', './dist/angular'], - [['app', 'public', 'remix.config.js', 'remix.env.d.ts', 'sandbox.config.js', 'tsconfig.json', 'package.json'], 'remix', 'npm install', 'npm run build', './build'], - [['public', 'src', 'astro.config.mjs', 'package-lock.json', 'package.json', 'tsconfig.json'], 'astro', 'npm install', 'npm run build', './dist'], - [['src', 'static', 'scripts', 'eslint.config.js', 'package.json', 'pnpm-lock.yaml', 'svelte.config.js', 'tsconfig.js', 'vite.config.js', 'vite.config.lib.js'], 'sveltekit', 'npm install', 'npm run build', './build'], + [['src', 'types', 'makefile', 'components.js', 'debug.js', 'package.json', 'svelte.config.js'], 'sveltekit', 'pnpm install', 'pnpm run build', './build'], + [['app', 'backend', 'public', 'Dockerfile', 'docker-compose.yml', 'ecosystem.config.js', 'middleware.ts', 'next.config.js', 'package-lock.json', 'package.json', 'server.js', 'tsconfig.json'], 'nextjs', 'pnpm install', 'pnpm run build', './.next'], + [['assets', 'components', 'layouts', 'pages', 'babel.config.js', 'error.vue', 'nuxt.config.js', 'yarn.lock'], 'nuxt', 'pnpm install', 'pnpm run build', './output'], + [['lynx.config.js'], 'lynx', 'pnpm install', 'pnpm run build', './dist'], + [['src', 'package.json', 'tsconfig.json', 'angular.json', 'logo.png'], 'angular', 'pnpm install', 'pnpm run build', './dist/angular'], + [['app', 'public', 'remix.config.js', 'remix.env.d.ts', 'sandbox.config.js', 'tsconfig.json', 'package.json'], 'remix', 'pnpm install', 'pnpm run build', './build'], + [['public', 'src', 'astro.config.mjs', 'package-lock.json', 'package.json', 'tsconfig.json'], 'astro', 'pnpm install', 'pnpm run build', './dist'], + [['src', 'static', 'scripts', 'eslint.config.js', 'package.json', 'pnpm-lock.yaml', 'svelte.config.js', 'tsconfig.js', 'vite.config.js', 'vite.config.lib.js'], 'sveltekit', 'pnpm install', 'pnpm run build', './build'], [['index.html', 'style.css'], null, null, null, null], // Test for FAILURE ]; } @@ -452,7 +452,7 @@ public function testTanStackStartDetectionWithDevPackages(): void $this->assertSame('tanstack-start', $detectedFramework->getName()); $this->assertSame('pnpm install', $detectedFramework->getInstallCommand()); - $this->assertSame('pnpm build', $detectedFramework->getBuildCommand()); + $this->assertSame('pnpm run build', $detectedFramework->getBuildCommand()); } /**