Socket
Socket
Sign inDemoInstall

@sveltejs/adapter-auto

Package Overview
Dependencies
1
Maintainers
4
Versions
108
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 1.0.0-next.87 to 1.0.0-next.88

103

index.js

@@ -0,2 +1,7 @@

import { execSync } from 'child_process';
import { pathToFileURL } from 'url';
import { resolve } from 'import-meta-resolve';
import { adapters } from './adapters.js';
import { dirname, join } from 'path';
import { existsSync } from 'fs';

@@ -6,2 +11,40 @@ /** @type {import('./index').default} */

/** @type {Record<string, (name: string) => string>} */
const commands = {
npm: (name) => `npm install -D ${name}`,
pnpm: (name) => `pnpm add -D ${name}`,
yarn: (name) => `yarn add -D ${name}`
};
function detect_lockfile() {
let dir = process.cwd();
do {
if (existsSync(join(dir, 'pnpm-lock.yaml'))) return 'pnpm';
if (existsSync(join(dir, 'yarn.lock'))) return 'yarn';
if (existsSync(join(dir, 'package-lock.json'))) return 'npm';
} while (dir !== (dir = dirname(dir)));
return 'npm';
}
function detect_package_manager() {
const manager = detect_lockfile();
try {
execSync(`${manager} --version`);
return manager;
} catch {
return 'npm';
}
}
/** @param {string} name */
async function import_from_cwd(name) {
const cwd = pathToFileURL(process.cwd()).href;
const url = await resolve(name, cwd + '/x.js');
return import(url);
}
for (const candidate of adapters) {

@@ -13,16 +56,3 @@ if (candidate.test()) {

try {
module = await import(candidate.module);
fn = () => {
const adapter = module.default();
return {
...adapter,
adapt: (builder) => {
builder.log.info(`Detected environment: ${candidate.name}. Using ${candidate.module}`);
return adapter.adapt(builder);
}
};
};
break;
module = await import_from_cwd(candidate.module);
} catch (error) {

@@ -33,9 +63,44 @@ if (

) {
throw new Error(
`It looks like ${candidate.module} is not installed. Please install it and try building your project again.`
);
const package_manager = detect_package_manager();
const command = commands[package_manager](candidate.module);
try {
console.log(`Installing ${candidate.module}...`);
execSync(command, {
stdio: 'inherit',
env: {
...process.env,
NODE_ENV: undefined
}
});
module = await import_from_cwd(candidate.module);
console.log(`Successfully installed ${candidate.module}.`);
console.warn(
`\nIf you plan on staying on this deployment platform, consider replacing @sveltejs/adapter-auto with ${candidate.module}. This will give you faster and more robust installs, and more control over deployment configuration.\n`
);
} catch (e) {
throw new Error(
`Could not install ${candidate.module}. Please install it yourself by adding it to your package.json's devDependencies and try building your project again.`
);
}
} else {
throw error;
}
}
throw error;
}
fn = () => {
const adapter = module.default();
return {
...adapter,
adapt: (builder) => {
builder.log.info(`Detected environment: ${candidate.name}. Using ${candidate.module}`);
return adapter.adapt(builder);
}
};
};
break;
}

@@ -42,0 +107,0 @@ }

10

package.json
{
"name": "@sveltejs/adapter-auto",
"version": "1.0.0-next.87",
"version": "1.0.0-next.88",
"repository": {

@@ -27,7 +27,2 @@ "type": "git",

],
"dependencies": {
"@sveltejs/adapter-cloudflare": "1.0.0-next.40",
"@sveltejs/adapter-netlify": "1.0.0-next.84",
"@sveltejs/adapter-vercel": "1.0.0-next.81"
},
"devDependencies": {

@@ -37,2 +32,5 @@ "@types/node": "^16.11.68",

},
"dependencies": {
"import-meta-resolve": "^2.1.0"
},
"scripts": {

@@ -39,0 +37,0 @@ "lint": "prettier --check . --config ../../.prettierrc --ignore-path .gitignore",

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc