Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
function resolveWebDependency(dep: string, isExplicit: boolean): DependencyLoc {
// if the path includes a file extension, just use it
if (path.extname(dep)) {
const isJSFile = ['.js', '.mjs', '.cjs'].includes(path.extname(dep));
return {
type: isJSFile ? 'JS' : 'ASSET',
loc: resolveFrom(cwd, dep),
};
}
const depManifestLoc = resolveFrom(cwd, `${dep}/package.json`);
const depManifest = require(depManifestLoc);
let foundEntrypoint: string =
depManifest['browser:module'] || depManifest.module || depManifest.browser;
// If the package was a part of the explicit whitelist, fallback to it's main CJS entrypoint.
if (!foundEntrypoint && isExplicit) {
foundEntrypoint = depManifest.main || 'index.js';
}
if (!foundEntrypoint) {
throw new ErrorWithHint(
`dependency "${dep}" has no native "module" entrypoint.`,
chalk.italic(
`Tip: Find modern, web-ready packages at ${chalk.underline('https://www.pika.dev')}`,
}
}
}
);
const optionsBase = {};
if (cli.flags.config) {
// Should check these possibilities:
// a. name of a node_module
// b. absolute path
// c. relative path relative to `process.cwd()`.
// If none of the above work, we'll try a relative path starting
// in `process.cwd()`.
optionsBase.configFile =
resolveFrom(process.cwd(), cli.flags.config) ||
path.join(process.cwd(), cli.flags.config);
}
Promise.resolve()
.then(() => Object.assign({}, optionsBase))
.then(options => standalone(options))
.then(output => {
if (cli.input.length === 0) {
throw new Error("Require `dest` argument");
}
const dest = path.resolve(cli.input.pop());
return Promise.resolve().then(() => fs.outputFile(dest, output));
})
.catch(error => {
test('verifyEnv() can use cache', async t => {
const dir = path.join(tmpDir, 'use-cache')
fse.copySync(fixture('verifier', 'pkg'), dir)
const plugin = resolveFrom(dir, './plugin.js')
const cache = prepareCache()
const verifier = await (await fromDirectory(dir)).createVerifier()
await verifier.verifyEnv(null, null, cache)
t.deepEqual(Array.from(cache.dependencyHashes.keys()), [
plugin
])
t.deepEqual(Array.from(cache.fileExistence.keys()), [
path.join(dir, '.babelrc'),
path.join(dir, '.babelrc.js')
])
t.deepEqual(Array.from(cache.files.keys()), [
path.join(dir, 'extends.json5'),
path.join(dir, 'package.json'),
plugin
function getCoreModulePath() {
const pkgPath = resolveFrom(workDir, '@sanity/core')
if (pkgPath) {
return pkgPath
}
const hasManifest = fs.existsSync(path.join(workDir, 'sanity.json'))
if (hasManifest && process.argv.indexOf('install') === -1) {
console.warn(chalk.yellow([
'@sanity/core not installed in current project',
'Project-specific commands not available until you run `sanity install`'
].join('\n')))
}
return undefined
}
public loadCommand (
commandPath: string,
): { command: CommandConstructorContract, commandPath: string } {
const absPath = resolveFrom(this.basePath, commandPath)
const command = esmRequire(absPath)
if (!command.name) {
throw CommandValidationException.invalidManifestExport(commandPath)
}
command.$boot()
return {
command,
commandPath,
}
}
},
resolve: {
modules: [
NODE_MODULES,
SRC,
DIST,
...[NODE_MODULES, SRC, DIST].map(d =>
DIST.startsWith(ROOT) ? path.resolve(__dirname, d) : path.resolve(d)
),
'node_modules',
],
extensions: ['.wasm', '.mjs', '.js', '.json', '.jsx'],
alias: {
react$: resolveFrom(config.paths.NODE_MODULES, 'react'),
'react-dom$': resolveFrom(config.paths.NODE_MODULES, 'react-dom'),
'react-universal-component': resolveFrom(
__dirname,
'react-universal-component'
),
},
},
externals: [],
target: undefined,
plugins: [
new webpack.EnvironmentPlugin(process.env),
extrackCSSChunks,
new CaseSensitivePathsPlugin(),
analyze && new BundleAnalyzerPlugin(),
].filter(d => d),
devtool: debug || config.productionSourceMaps ? 'source-map' : false,
}
}
ImportDeclaration(path, { file, opts = {} }) {
const options = { ...defaultOptions, ...opts };
const { value } = path.node.source;
const ext = extname(value);
if (options.extensions.includes(ext) && getVariableName(path)) {
const rootPath = file.opts.sourceRoot || process.cwd();
const scriptDirectory = dirname(resolve(file.opts.filename));
const cssfilePath = resolveFrom(scriptDirectory, value);
const cssString = getCSS(cssfilePath);
const varName = getVariableName(path);
const { bindings } = path.scope;
const styleObject = StyleSheet.parse(cssString);
validateReferences(bindings[varName].referencePaths, styleObject);
if (!options.outDir) {
let lastImportIndex = getLastImportIndex(path);
let pfStylesImportIndex = getPackageImportIndex(path);
if (pfStylesImportIndex === -1) {
path.getSibling(lastImportIndex).insertAfter(createStyleSheetImport());
lastImportIndex++;
pfStylesImportIndex = lastImportIndex;
}
import alias from 'rollup-plugin-alias'
import resolve from 'resolve-from'
import postcss from 'rollup-plugin-postcss'
export default {
input: 'src/index.js',
plugins: [
postcss(),
babel(),
nodejs({
jsnext: true,
main: true,
}),
commonjs(),
alias({
'matches-selector': resolve(__dirname, 'component-matches-selector'),
'query': resolve(__dirname, 'component-query'),
}),
],
}
map(id => {
try {
return require.resolve(id);
} catch (ignored) {
return resolveFrom(process.cwd(), id);
}
}),
debug(pluginPath => `resolved plugin "${pluginId}" to ${pluginPath}`),