Socket
Socket
Sign inDemoInstall

unimported

Package Overview
Dependencies
Maintainers
1
Versions
47
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

unimported - npm Package Compare versions

Comparing version 1.0.1 to 1.0.2

44

dist/meta.js

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

const ensureArray_1 = require("./ensureArray");
const traverse_1 = require("./traverse");
function getProjectType(projectPath) {

@@ -70,16 +71,2 @@ return __awaiter(this, void 0, void 0, function* () {

exports.getDependencies = getDependencies;
function resolvePath(path, context) {
return __awaiter(this, void 0, void 0, function* () {
if (yield fs.exists(path_1.join(context.cwd, path))) {
return path_1.join(context.cwd, path);
}
for (const ext of context.extensions) {
const absolutePath = path_1.join(context.cwd, `${path}${ext}`);
if (yield fs.exists(absolutePath)) {
return absolutePath;
}
}
return null;
});
}
function isString(value) {

@@ -96,19 +83,22 @@ return typeof value === 'string';

}
const client = yield traverse_1.resolveImport(packageJson.meteor.mainModule.client, projectPath, context);
const server = yield traverse_1.resolveImport(packageJson.meteor.mainModule.server, projectPath, context);
return [
yield resolvePath(packageJson.meteor.mainModule.client, context),
yield resolvePath(packageJson.meteor.mainModule.server, context),
client.type !== 'unresolved' && client.path,
server.type !== 'unresolved' && server.path,
].filter(isString);
}
const options = ['src/index', 'src/main', 'index', 'main']
.map((x) => context.extensions.map((ext) => `${x}${ext}`))
.reduce((acc, next) => {
acc.push(...next);
return acc;
}, []);
const { source, main } = packageJson;
for (const option of [source, ...options, main]) {
const resolved = yield resolvePath(option, context);
if (resolved) {
return [resolved];
}
const options = [
source,
'./src/index',
'./src/main',
'./index',
'./main',
main,
];
const resolved = yield Promise.all(options.map((x) => traverse_1.resolveImport(`${x}`, projectPath, context)));
const entry = resolved.find((x) => x.type === 'source_file');
if (entry) {
return [entry.path];
}

@@ -115,0 +105,0 @@ throw new Error('could not find entry point');

@@ -24,2 +24,3 @@ import { Context } from './index';

};
export declare function resolveImport(path: string, cwd: string, context: Context): ResolvedResult;
export declare function traverse(path: string | string[], context: Context, result?: {

@@ -26,0 +27,0 @@ unresolved: Set<string>;

@@ -76,2 +76,17 @@ "use strict";

}
// last attempt, try prefix the path with ./, `import 'index' to `import './index'`
// can be useful for the entry files
try {
return {
type: 'source_file',
path: resolve_1.default
.sync(`./${path}`, {
basedir: cwd,
extensions: context.extensions,
})
.replace(/\\/g, '/'),
};
}
catch (e) { }
// if nothing else works out :(
return {

@@ -82,2 +97,3 @@ type: 'unresolved',

}
exports.resolveImport = resolveImport;
function parse(path, context) {

@@ -84,0 +100,0 @@ return __awaiter(this, void 0, void 0, function* () {

{
"name": "unimported",
"version": "1.0.1",
"version": "1.0.2",
"description": "Scans your nodejs project folder and shows obsolete files and modules",

@@ -5,0 +5,0 @@ "main": "./dist/unimported.js",

@@ -5,2 +5,3 @@ import * as fs from './fs';

import { Context } from './index';
import { resolveImport } from './traverse';

@@ -63,20 +64,2 @@ export async function getProjectType(

async function resolvePath(
path: string,
context: Context,
): Promise<string | null> {
if (await fs.exists(join(context.cwd, path))) {
return join(context.cwd, path);
}
for (const ext of context.extensions) {
const absolutePath = join(context.cwd, `${path}${ext}`);
if (await fs.exists(absolutePath)) {
return absolutePath;
}
}
return null;
}
function isString(value): value is string {

@@ -99,22 +82,36 @@ return typeof value === 'string';

const client = await resolveImport(
packageJson.meteor.mainModule.client,
projectPath,
context,
);
const server = await resolveImport(
packageJson.meteor.mainModule.server,
projectPath,
context,
);
return [
await resolvePath(packageJson.meteor.mainModule.client, context),
await resolvePath(packageJson.meteor.mainModule.server, context),
client.type !== 'unresolved' && client.path,
server.type !== 'unresolved' && server.path,
].filter(isString);
}
const options = ['src/index', 'src/main', 'index', 'main']
.map((x) => context.extensions.map((ext) => `${x}${ext}`))
.reduce((acc, next) => {
acc.push(...next);
return acc;
}, []);
const { source, main } = packageJson;
const options = [
source,
'./src/index',
'./src/main',
'./index',
'./main',
main,
];
for (const option of [source, ...options, main]) {
const resolved = await resolvePath(option, context);
if (resolved) {
return [resolved];
}
const resolved = await Promise.all(
options.map((x) => resolveImport(`${x}`, projectPath, context)),
);
const entry = resolved.find((x) => x.type === 'source_file');
if (entry) {
return [entry.path];
}

@@ -121,0 +118,0 @@

@@ -63,3 +63,3 @@ import { dirname, extname } from 'path';

function resolveImport(
export function resolveImport(
path: string,

@@ -108,2 +108,17 @@ cwd: string,

// last attempt, try prefix the path with ./, `import 'index' to `import './index'`
// can be useful for the entry files
try {
return {
type: 'source_file',
path: resolve
.sync(`./${path}`, {
basedir: cwd,
extensions: context.extensions,
})
.replace(/\\/g, '/'),
};
} catch (e) {}
// if nothing else works out :(
return {

@@ -110,0 +125,0 @@ type: 'unresolved',

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