Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

client-side-library-resolver

Package Overview
Dependencies
Maintainers
1
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

client-side-library-resolver - npm Package Compare versions

Comparing version 1.1.1 to 1.2.0

6

CHANGELOG.md

@@ -21,2 +21,6 @@ # Changelog

## [1.1.1] - 2019-07-21
-
-
## [1.2.0] - 2019-07-21
# Added
- Adds support for CSS minifying, via the `Library.fileType` property.

4

lib/index.d.ts

@@ -1,4 +0,4 @@

export { default as Library, specialFiles, specialVersions } from './Library';
export { default as Library, SpecialFiles, SpecialVersions, FileTypes } from './Library';
export { default as LocalRegistry } from './LocalRegistry';
export { default as Registry, LibraryDoesNotExist, VersionDoesNotMatch, NoMain } from './Registry';
export { default as Registry, LibraryDoesNotExist, VersionDoesNotMatch, NoMain, UnsupportedFileType } from './Registry';
export { default as unpkgRegistry } from './unpkgRegistry';

@@ -5,4 +5,5 @@ "use strict";

exports.Library = Library_1.default;
exports.specialFiles = Library_1.specialFiles;
exports.specialVersions = Library_1.specialVersions;
exports.SpecialFiles = Library_1.SpecialFiles;
exports.SpecialVersions = Library_1.SpecialVersions;
exports.FileTypes = Library_1.FileTypes;
var LocalRegistry_1 = require("./LocalRegistry");

@@ -15,4 +16,5 @@ exports.LocalRegistry = LocalRegistry_1.default;

exports.NoMain = Registry_1.NoMain;
exports.UnsupportedFileType = Registry_1.UnsupportedFileType;
var unpkgRegistry_1 = require("./unpkgRegistry");
exports.unpkgRegistry = unpkgRegistry_1.default;
//# sourceMappingURL=index.js.map

@@ -1,13 +0,50 @@

export declare enum specialFiles {
mainFile = "~MAIN_FILE~"
/**
* Special files that can exist within the library.
*/
export declare enum SpecialFiles {
/**
* The file at the `main` property of package.json.
*/
mainFile = "%manifest.main%"
}
export declare enum specialVersions {
/**
* Non-semver versions of special significance.
*/
export declare enum SpecialVersions {
/**
* The most recent version of the package.
*/
latest = "latest"
}
/**
* File types that are supported.
*/
export declare enum FileTypes {
/**
* JavaScript.
*/
js = "js",
/**
* CSS.
*/
css = "css"
}
/**
* Represents a single software package within the repository. Can either be CSS or JS.
*/
export default class Library {
name: string;
version: string | specialVersions;
path: string | specialFiles;
version: string | SpecialVersions;
path: string | SpecialFiles;
minifiedPath?: string;
constructor(name: string, version?: string | specialVersions, path?: string | specialFiles, minifiedPath?: string);
fileType: FileTypes;
/**
*
* @param name - Name of the software package (e.g. `bootstrap`).
* @param version - The version of the software to match against. Should be semver compatible (e.g. `1.0.0`, `1` or `latest`). Defaults to `latest`.
* @param path - Path to the main (non-minified) copy of the file. Defaults to the `main` property in the package.json file.
* @param minifiedPath - Path to the minified copy of the file. Will attempt to minify the file at the `main` path if not provided.
* @param fileType - Indicates the file type of the library, defaults to `js`.
*/
constructor(name: string, version?: string | SpecialVersions, path?: string | SpecialFiles, minifiedPath?: string, fileType?: FileTypes);
}
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var specialFiles;
(function (specialFiles) {
specialFiles["mainFile"] = "~MAIN_FILE~";
})(specialFiles = exports.specialFiles || (exports.specialFiles = {}));
var specialVersions;
(function (specialVersions) {
specialVersions["latest"] = "latest";
})(specialVersions = exports.specialVersions || (exports.specialVersions = {}));
/**
* Special files that can exist within the library.
*/
var SpecialFiles;
(function (SpecialFiles) {
/**
* The file at the `main` property of package.json.
*/
SpecialFiles["mainFile"] = "%manifest.main%";
})(SpecialFiles = exports.SpecialFiles || (exports.SpecialFiles = {}));
/**
* Non-semver versions of special significance.
*/
var SpecialVersions;
(function (SpecialVersions) {
/**
* The most recent version of the package.
*/
SpecialVersions["latest"] = "latest";
})(SpecialVersions = exports.SpecialVersions || (exports.SpecialVersions = {}));
/**
* File types that are supported.
*/
var FileTypes;
(function (FileTypes) {
/**
* JavaScript.
*/
FileTypes["js"] = "js";
/**
* CSS.
*/
FileTypes["css"] = "css";
})(FileTypes = exports.FileTypes || (exports.FileTypes = {}));
/**
* Represents a single software package within the repository. Can either be CSS or JS.
*/
class Library {
constructor(name, version = specialVersions.latest, path = specialFiles.mainFile, minifiedPath) {
/**
*
* @param name - Name of the software package (e.g. `bootstrap`).
* @param version - The version of the software to match against. Should be semver compatible (e.g. `1.0.0`, `1` or `latest`). Defaults to `latest`.
* @param path - Path to the main (non-minified) copy of the file. Defaults to the `main` property in the package.json file.
* @param minifiedPath - Path to the minified copy of the file. Will attempt to minify the file at the `main` path if not provided.
* @param fileType - Indicates the file type of the library, defaults to `js`.
*/
constructor(name, version = SpecialVersions.latest, path = SpecialFiles.mainFile, minifiedPath, fileType = FileTypes.js) {
this.name = name;

@@ -17,2 +54,3 @@ this.version = version;

this.minifiedPath = minifiedPath;
this.fileType = fileType;
}

@@ -19,0 +57,0 @@ }

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

throw new Registry_1.LibraryDoesNotExist(lib);
if ((typeof (lib.version) !== 'undefined' && lib.version !== Library_1.specialVersions.latest) && !semver.satisfies(packageJson.version, lib.version)) {
if ((typeof (lib.version) !== 'undefined' && lib.version !== Library_1.SpecialVersions.latest) && !semver.satisfies(packageJson.version, lib.version)) {
throw new Registry_1.VersionDoesNotMatch(lib, packageJson.version);
}
const libPath = path.join(libDir, (lib.path === Library_1.specialFiles.mainFile ?
const libPath = path.join(libDir, (lib.path === Library_1.SpecialFiles.mainFile ?
packageJson.main :

@@ -62,3 +62,3 @@ lib.path));

const packageJson = await this.getManifest(lib);
if ((typeof (lib.version) !== 'undefined' && lib.version !== Library_1.specialVersions.latest) && !semver.satisfies(packageJson.version, lib.version)) {
if ((typeof (lib.version) !== 'undefined' && lib.version !== Library_1.SpecialVersions.latest) && !semver.satisfies(packageJson.version, lib.version)) {
throw new Registry_1.VersionDoesNotMatch(lib, packageJson.version);

@@ -65,0 +65,0 @@ }

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

import { default as Library } from './Library';
import * as CleanCSS from 'clean-css';
import { default as Library, FileTypes } from './Library';
export declare class NoMinifiedPath extends Error {

@@ -19,3 +20,8 @@ lib: Library;

}
export declare class UnsupportedFileType extends Error {
constructor(fileType: FileTypes | string);
}
export default abstract class Registry {
protected cleanCSS: CleanCSS.MinifierOutput;
constructor();
/**

@@ -22,0 +28,0 @@ * Retrieves the the full path to a given library at a given version. Will use the file located at the `main` property of the `package.json` associated with the library if `lib.path` is not set.

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const uglify = require("uglify-js");
const CleanCSS = require("clean-css");
const Library_1 = require("./Library");
class NoMinifiedPath extends Error {

@@ -33,3 +35,12 @@ constructor(lib) {

exports.NoMain = NoMain;
class UnsupportedFileType extends Error {
constructor(fileType) {
super(`File type ${fileType} not supported.`);
}
}
exports.UnsupportedFileType = UnsupportedFileType;
class Registry {
constructor() {
this.cleanCSS = new CleanCSS();
}
/**

@@ -40,3 +51,11 @@ * Retrieves the full text for the minified copy of a given library.

const libText = await this.get(lib);
return uglify.minify(libText).code;
if (lib.fileType === Library_1.FileTypes.js) {
return uglify.minify(libText).code;
}
else if (lib.fileType === Library_1.FileTypes.css) {
return this.cleanCSS.minify(libText).styles;
}
else {
throw new UnsupportedFileType(lib.fileType);
}
}

@@ -43,0 +62,0 @@ }

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

try {
if (lib.version === Library_1.specialVersions.latest && lib.path === Library_1.specialFiles.mainFile) {
if (lib.version === Library_1.SpecialVersions.latest && lib.path === Library_1.SpecialFiles.mainFile) {
url = `${this.unpkgUrlBase}/${lib.name}`;
}
else if (lib.path === Library_1.specialFiles.mainFile) {
else if (lib.path === Library_1.SpecialFiles.mainFile) {
url = `${this.unpkgUrlBase}/${lib.name}@${lib.version}`;

@@ -45,3 +45,3 @@ }

const packageJson = await this.getManifest(lib);
let mainPath = (lib.path !== Library_1.specialFiles.mainFile) ? lib.path : ('/' + packageJson.main);
let mainPath = (lib.path !== Library_1.SpecialFiles.mainFile) ? lib.path : ('/' + packageJson.main);
url = `${this.unpkgUrlBase}/${lib.name}@${lib.version}${mainPath}`;

@@ -48,0 +48,0 @@ }

{
"name": "client-side-library-resolver",
"version": "1.1.1",
"version": "1.2.0",
"description": "Provides tools to seamlessly switch between sending CDN or locally stored modules to the browser.",

@@ -32,2 +32,3 @@ "main": "lib/index.js",

"@types/mocha": "^5.2.7",
"bootstrap": "^4.3.1",
"chai": "^4.2.0",

@@ -49,2 +50,3 @@ "chai-as-promised": "^7.1.1",

"dependencies": {
"@types/clean-css": "^4.2.1",
"@types/request": "^2.48.2",

@@ -54,2 +56,3 @@ "@types/request-promise-native": "^1.0.16",

"@types/uglify-js": "^3.0.4",
"clean-css": "^4.2.1",
"fs-extra": "^8.1.0",

@@ -56,0 +59,0 @@ "request": "^2.88.0",

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

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