Socket
Socket
Sign inDemoInstall

vite

Package Overview
Dependencies
Maintainers
1
Versions
569
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

vite - npm Package Compare versions

Comparing version 0.16.7 to 0.16.8

10

CHANGELOG.md

@@ -0,1 +1,11 @@

## [0.16.8](https://github.com/vuejs/vite/compare/v0.16.7...v0.16.8) (2020-05-23)
### Bug Fixes
* defaultRequestToFile should consider optimized modules ([#239](https://github.com/vuejs/vite/issues/239)) ([b5ddcdc](https://github.com/vuejs/vite/commit/b5ddcdcc65f62bf3fd50e487dc2d9bfa61624539))
* properly resolve file extensions ([aaf61f4](https://github.com/vuejs/vite/commit/aaf61f4d0d6843d0b34c9c75c4dec8a95e95b9d1)), closes [#237](https://github.com/vuejs/vite/issues/237)
## [0.16.7](https://github.com/vuejs/vite/compare/v0.16.6...v0.16.7) (2020-05-22)

@@ -2,0 +12,0 @@

10

dist/resolver.d.ts

@@ -15,3 +15,11 @@ export interface Resolver {

export declare const jsSrcRE: RegExp;
export declare function resolveBareModule(root: string, id: string, importer: string): string;
/**
* Redirects a bare module request to a full path under /@modules/
* It resolves a bare node module id to its full entry path so that relative
* imports from the entry can be correctly resolved.
* e.g.:
* - `import 'foo'` -> `import '/@modules/foo/dist/index.js'`
* - `import 'foo/bar/baz'` -> `import '/@modules/foo/bar/baz'`
*/
export declare function resolveBareModuleRequest(root: string, id: string, importer: string): string;
export declare function resolveOptimizedModule(root: string, id: string): string | undefined;

@@ -18,0 +26,0 @@ interface NodeModuleInfo {

107

dist/resolver.js

@@ -13,14 +13,22 @@ "use strict";

const chalk_1 = __importDefault(require("chalk"));
const debug = require('debug')('vite:resolve');
exports.supportedExts = ['.mjs', '.js', '.ts', '.jsx', '.tsx', '.json'];
const defaultRequestToFile = (publicPath, root) => {
if (serverPluginModuleResolve_1.moduleRE.test(publicPath)) {
const id = publicPath.replace(serverPluginModuleResolve_1.moduleRE, '');
const cachedModuleFilePath = serverPluginModuleResolve_1.idToFileMap.get(id);
if (cachedModuleFilePath) {
return cachedModuleFilePath;
const cachedNodeModule = serverPluginModuleResolve_1.idToFileMap.get(id);
if (cachedNodeModule) {
return cachedNodeModule;
}
const resolved = resolveNodeModuleFile(root, id);
if (resolved) {
serverPluginModuleResolve_1.idToFileMap.set(id, resolved);
return resolved;
// try to resolve from optimized modules
const optimizedModule = resolveOptimizedModule(root, id);
if (optimizedModule) {
return optimizedModule;
}
// try to resolve from normal node_modules
const nodeModule = resolveNodeModuleFile(root, id);
if (nodeModule) {
serverPluginModuleResolve_1.idToFileMap.set(id, nodeModule);
return nodeModule;
}
}

@@ -36,23 +44,22 @@ return path_1.default.join(root, publicPath.slice(1));

};
exports.supportedExts = ['.mjs', '.js', '.ts', '.jsx', '.tsx', '.json'];
const debug = require('debug')('vite:resolve');
const isFile = (file) => {
try {
return fs_1.default.statSync(file).isFile();
}
catch (e) {
return false;
}
};
exports.resolveExt = (id) => {
const cleanId = utils_1.cleanUrl(id);
if (!path_1.default.extname(cleanId)) {
if (!isFile(cleanId)) {
let inferredExt = '';
for (const ext of exports.supportedExts) {
try {
// foo -> foo.js
fs_1.default.statSync(cleanId + ext);
if (isFile(cleanId + ext)) {
inferredExt = ext;
break;
}
catch (e) {
try {
// foo -> foo/index.js
fs_1.default.statSync(path_1.default.join(cleanId, '/index' + ext));
inferredExt = '/index' + ext;
break;
}
catch (e) { }
if (isFile(path_1.default.join(cleanId, '/index' + ext))) {
inferredExt = '/index' + ext;
break;
}

@@ -110,3 +117,11 @@ }

const deepImportRE = /^([^@][^/]*)\/|^(@[^/]+\/[^/]+)\//;
function resolveBareModule(root, id, importer) {
/**
* Redirects a bare module request to a full path under /@modules/
* It resolves a bare node module id to its full entry path so that relative
* imports from the entry can be correctly resolved.
* e.g.:
* - `import 'foo'` -> `import '/@modules/foo/dist/index.js'`
* - `import 'foo/bar/baz'` -> `import '/@modules/foo/bar/baz'`
*/
function resolveBareModuleRequest(root, id, importer) {
const optimized = resolveOptimizedModule(root, id);

@@ -133,6 +148,10 @@ if (optimized) {

}
return id;
}
return id;
else {
// append import query for non-js deep imports
return id + (utils_1.queryRE.test(id) ? '&import' : '?import');
}
}
exports.resolveBareModule = resolveBareModule;
exports.resolveBareModuleRequest = resolveBareModuleRequest;
const viteOptimizedMap = new Map();

@@ -167,18 +186,2 @@ function resolveOptimizedModule(root, id) {

catch (e) { }
if (!pkgPath) {
// if the above resolve failed, it's either the package is not installed,
// or the package has explicit exports field preventing us from resolving
// its package.json. Try to resovle the package.json's path by sniffing
// the node_modules in the path.
try {
const entryPath = utils_1.resolveFrom(root, id);
if (entryPath) {
const moduleIndex = entryPath.lastIndexOf(path_1.default.join(`node_modules`, id));
if (moduleIndex > 0) {
pkgPath = path_1.default.join(entryPath.slice(0, moduleIndex), 'node_modules', id, 'package.json');
}
}
}
catch (e) { }
}
if (pkgPath) {

@@ -235,24 +238,12 @@ // if yes, this is a entry import. resolve entry file

}
let resolved;
if (!path_1.default.extname(id)) {
for (const ext of exports.supportedExts) {
try {
resolved = utils_1.resolveFrom(root, id + ext);
}
catch (e) { }
if (resolved) {
break;
}
}
try {
const resolved = utils_1.resolveFrom(root, id);
nodeModulesFileMap.set(id, resolved);
return resolved;
}
if (!resolved) {
try {
resolved = utils_1.resolveFrom(root, id);
}
catch (e) { }
catch (e) {
// error will be reported downstream
}
nodeModulesFileMap.set(id, resolved);
return resolved;
}
exports.resolveNodeModuleFile = resolveNodeModuleFile;
//# sourceMappingURL=resolver.js.map

@@ -14,2 +14,4 @@ "use strict";

const chalk_1 = __importDefault(require("chalk"));
const slash_1 = __importDefault(require("slash"));
const serverPluginModuleResolve_1 = require("./serverPluginModuleResolve");
const debug = require('debug')('vite:rewrite');

@@ -167,23 +169,17 @@ const rewriteCache = new lru_cache_1.default({ max: 1024 });

// imports from it (including source map urls) can work correctly
let resolvedModulePath = resolver_1.resolveBareModule(root, id, importer);
const ext = path_1.default.extname(resolvedModulePath);
if (ext && !resolver_1.jsSrcRE.test(ext)) {
resolvedModulePath += `?import`;
}
return `/@modules/${resolvedModulePath}`;
return `/@modules/${resolver_1.resolveBareModuleRequest(root, id, importer)}`;
}
else {
// 1. relative to absolute
// ./foo -> /some/path/foo
let { pathname, query } = utils_1.resolveRelativeRequest(importer, id);
// append an extension to extension-less imports
if (!path_1.default.extname(pathname)) {
const file = resolver.requestToFile(pathname);
const indexMatch = file.match(/\/index\.\w+$/);
if (indexMatch) {
pathname = pathname.replace(/\/(index)?$/, '') + indexMatch[0];
}
else {
pathname += path_1.default.extname(file);
}
// 2. if this is a relative import between files under /@modules/, preserve
// them as-is
if (serverPluginModuleResolve_1.moduleRE.test(pathname)) {
return pathname;
}
// mark non-src imports
// 3. resolve extensions.
const file = resolver.requestToFile(pathname);
pathname = '/' + slash_1.default(path_1.default.relative(root, file));
// 4. mark non-src imports
const ext = path_1.default.extname(pathname);

@@ -193,3 +189,3 @@ if (ext && !resolver_1.jsSrcRE.test(pathname)) {

}
// force re-fetch dirty imports by appending timestamp
// 5. force re-fetch dirty imports by appending timestamp
if (timestamp) {

@@ -196,0 +192,0 @@ const dirtyFiles = serverPluginHmr_1.hmrDirtyFilesMap.get(timestamp);

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

import postcssrc from 'postcss-load-config';
import { SFCAsyncStyleCompileOptions, SFCStyleCompileResults } from '@vue/compiler-sfc';

@@ -7,2 +8,4 @@ export declare const urlRE: RegExp;

export declare function compileCss(root: string, publicPath: string, { source, filename, scoped, modules, preprocessLang }: SFCAsyncStyleCompileOptions): Promise<SFCStyleCompileResults | string>;
declare type PostCSSConfigResult = ReturnType<typeof postcssrc> extends Promise<infer T> ? T : never;
export declare function loadPostcssConfig(root: string): Promise<PostCSSConfigResult | null>;
export {};

@@ -7,6 +7,6 @@ "use strict";

const path_1 = __importDefault(require("path"));
const chalk_1 = __importDefault(require("chalk"));
const transformUtils_1 = require("./transformUtils");
const pathUtils_1 = require("./pathUtils");
const resolveVue_1 = require("./resolveVue");
const resolvePostCssConfig_1 = require("./resolvePostCssConfig");
const hash_sum_1 = __importDefault(require("hash-sum"));

@@ -38,3 +38,3 @@ exports.urlRE = /(url\(\s*['"]?)([^"')]+)(["']?\s*\))/;

const id = hash_sum_1.default(publicPath);
const postcssConfig = await resolvePostCssConfig_1.loadPostcssConfig(root);
const postcssConfig = await loadPostcssConfig(root);
const { compileStyleAsync } = resolveVue_1.resolveCompiler(root);

@@ -65,2 +65,20 @@ if (publicPath.endsWith('.css') && !modules && !postcssConfig) {

exports.compileCss = compileCss;
let cachedPostcssConfig;
async function loadPostcssConfig(root) {
if (cachedPostcssConfig !== undefined) {
return cachedPostcssConfig;
}
try {
const load = require('postcss-load-config');
return (cachedPostcssConfig = await load({}, root));
}
catch (e) {
if (!/No PostCSS Config found/.test(e.message)) {
console.error(chalk_1.default.red(`[vite] Error loading postcss config:`));
console.error(e);
}
return (cachedPostcssConfig = null);
}
}
exports.loadPostcssConfig = loadPostcssConfig;
//# sourceMappingURL=cssUtils.js.map

@@ -5,2 +5,1 @@ export * from './fsUtils';

export * from './resolveVue';
export * from './resolvePostCssConfig';

@@ -10,3 +10,2 @@ "use strict";

__export(require("./resolveVue"));
__export(require("./resolvePostCssConfig"));
//# sourceMappingURL=index.js.map

@@ -9,3 +9,5 @@ "use strict";

const querystring_1 = __importDefault(require("querystring"));
exports.resolveFrom = (root, id) => require.resolve(id, { paths: [root] });
const resolve_1 = __importDefault(require("resolve"));
const resolver_1 = require("../resolver");
exports.resolveFrom = (root, id) => resolve_1.default.sync(id, { basedir: root, extensions: resolver_1.supportedExts });
exports.queryRE = /\?.*$/;

@@ -12,0 +14,0 @@ exports.hashRE = /\#.*$/;

{
"name": "vite",
"version": "0.16.7",
"version": "0.16.8",
"license": "MIT",

@@ -52,7 +52,2 @@ "author": "Evan You",

},
"jest": {
"watchPathIgnorePatterns": [
"<rootDir>/test/temp"
]
},
"dependencies": {

@@ -93,2 +88,3 @@ "@babel/parser": "^7.9.4",

"postcss-modules": "^2.0.0",
"resolve": "^1.17.0",
"rollup": "^2.7.2",

@@ -119,2 +115,3 @@ "rollup-plugin-terser": "^5.3.0",

"lodash-es": "^4.17.15",
"moment": "^2.26.0",
"npm-run-all": "^4.1.5",

@@ -121,0 +118,0 @@ "postcss-nesting": "^7.0.1",

SocketSocket SOC 2 Logo

Product

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

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc