-
Notifications
You must be signed in to change notification settings - Fork 916
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* add true snowpack.lock.json support * update snapshots
- Loading branch information
1 parent
8218e07
commit 76d3e2b
Showing
51 changed files
with
163 additions
and
346 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,7 +8,6 @@ | |
"cdn", | ||
"sdk" | ||
], | ||
"private": true, | ||
"author": "Fred K. Schott <[email protected]>", | ||
"license": "MIT", | ||
"publishConfig": { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,31 +1,33 @@ | ||
import {promises as fs} from 'fs'; | ||
import {send} from 'httpie'; | ||
import {cyan, dim, underline} from 'kleur/colors'; | ||
import path from 'path'; | ||
import {generateImportMap} from 'skypack'; | ||
import {logger} from '../logger'; | ||
import {CommandOptions} from '../types/snowpack'; | ||
import {command as installCommand} from './install'; | ||
import {writeLockfile} from '../util'; | ||
|
||
export async function addCommand(addValue: string, commandOptions: CommandOptions) { | ||
const {cwd, config, pkgManifest} = commandOptions; | ||
const {cwd, lockfile} = commandOptions; | ||
let [pkgName, pkgSemver] = addValue.split('@'); | ||
if (!pkgSemver) { | ||
const installMessage = pkgSemver ? `${pkgName}@${pkgSemver}` : pkgName; | ||
logger.info(`fetching ${cyan(installMessage)} from Skypack CDN...`); | ||
if (!pkgSemver || pkgSemver === 'latest') { | ||
const {data} = await send('GET', `http://registry.npmjs.org/${pkgName}/latest`); | ||
pkgSemver = `^${data.version}`; | ||
} | ||
pkgManifest.webDependencies = pkgManifest.webDependencies || {}; | ||
pkgManifest.webDependencies[pkgName] = pkgSemver; | ||
config.webDependencies = config.webDependencies || {}; | ||
config.webDependencies[pkgName] = pkgSemver; | ||
await fs.writeFile(path.join(cwd, 'package.json'), JSON.stringify(pkgManifest, null, 2)); | ||
await installCommand(commandOptions); | ||
logger.info( | ||
`adding ${cyan( | ||
underline(`https://cdn.skypack.dev/${pkgName}@${pkgSemver}`), | ||
)} to your project lockfile. ${dim('(snowpack.lock.json)')}`, | ||
); | ||
const newLockfile = await generateImportMap({[pkgName]: pkgSemver}, lockfile || undefined); | ||
await writeLockfile(path.join(cwd, 'snowpack.lock.json'), newLockfile); | ||
} | ||
|
||
export async function rmCommand(addValue: string, commandOptions: CommandOptions) { | ||
const {cwd, config, pkgManifest} = commandOptions; | ||
const {cwd, lockfile} = commandOptions; | ||
let [pkgName] = addValue.split('@'); | ||
pkgManifest.webDependencies = pkgManifest.webDependencies || {}; | ||
delete pkgManifest.webDependencies[pkgName]; | ||
config.webDependencies = config.webDependencies || {}; | ||
delete config.webDependencies[pkgName]; | ||
await fs.writeFile(path.join(cwd, 'package.json'), JSON.stringify(pkgManifest, null, 2)); | ||
await installCommand(commandOptions); | ||
logger.info(`removing ${cyan(pkgName)} from project lockfile...`); | ||
const newLockfile = await generateImportMap({[pkgName]: null}, lockfile || undefined); | ||
await writeLockfile(path.join(cwd, 'snowpack.lock.json'), newLockfile); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
76d3e2b
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs: