liferay-npm-build-tools-common
Advanced tools
Comparing version 2.25.0 to 2.26.0
@@ -16,2 +16,7 @@ /** | ||
export declare type PkgManager = 'npm' | 'yarn' | null; | ||
/** Information on the preset being used */ | ||
export interface PresetInfo { | ||
name: string; | ||
isAutopreset: boolean; | ||
} | ||
/** | ||
@@ -64,2 +69,6 @@ * Describes a standard JS Toolkit project. | ||
/** | ||
* Get information about the preset in use | ||
*/ | ||
get presetInfo(): PresetInfo | undefined; | ||
/** | ||
* Get all available information about versions of plugins and presets used | ||
@@ -93,3 +102,3 @@ * for the build. | ||
*/ | ||
resolve(moduleName: string): any; | ||
resolve(moduleName: string): string; | ||
/** | ||
@@ -129,5 +138,4 @@ * Set program arguments so that some of them can be parsed as if they were | ||
*/ | ||
toolResolve(moduleName: string): any; | ||
_findAutopresets(): string[]; | ||
_loadDefaultPreset(): string; | ||
toolResolve(moduleName: string): string; | ||
_getAutopreset(): string | null; | ||
_loadNpmbundlerrc(): void; | ||
@@ -142,2 +150,4 @@ _loadPkgJson(): void; | ||
private _pkgManager; | ||
/** Info about preset in use */ | ||
private _presetInfo; | ||
/** Absolute path to project directory */ | ||
@@ -144,0 +154,0 @@ private _projectDir; |
@@ -136,2 +136,8 @@ "use strict"; | ||
/** | ||
* Get information about the preset in use | ||
*/ | ||
get presetInfo() { | ||
return this._presetInfo; | ||
} | ||
/** | ||
* Get all available information about versions of plugins and presets used | ||
@@ -278,13 +284,18 @@ * for the build. | ||
} | ||
_findAutopresets() { | ||
_getAutopreset() { | ||
const { dependencies = {}, devDependencies = {} } = this._pkgJson; | ||
return Object.keys({ | ||
const autopresets = Object.keys({ | ||
...dependencies, | ||
...devDependencies, | ||
}).reduce((autoPresets, pkgName) => { | ||
}).reduce((autopresets, pkgName) => { | ||
try { | ||
const { dependencies } = this.require(pkgName + '/package.json'); | ||
if (dependencies && dependencies['liferay-npm-bundler']) { | ||
autoPresets.push(pkgName); | ||
if (!dependencies || !dependencies['liferay-npm-bundler']) { | ||
return autopresets; | ||
} | ||
const mainModulePath = this.resolve(pkgName); | ||
if (!mainModulePath.toLowerCase().endsWith('.json')) { | ||
return autopresets; | ||
} | ||
autopresets.push(pkgName); | ||
} | ||
@@ -294,25 +305,11 @@ catch (err) { | ||
} | ||
return autoPresets; | ||
return autopresets; | ||
}, []); | ||
} | ||
_loadDefaultPreset() { | ||
let presetFilePath; | ||
const autoPresets = this._findAutopresets(); | ||
if (autoPresets.length > 1) { | ||
throw new Error('Multiple autopreset dependencies found in project (' + | ||
autoPresets + | ||
'): please remove the invalid ones or ' + | ||
if (autopresets.length > 1) { | ||
throw new Error('Multiple autopreset dependencies found in project ' + | ||
`(${autopresets}): please remove the invalid ones or ` + | ||
'explicitly define the preset to be used in the ' + | ||
'.npmbundlerrc file'); | ||
} | ||
else if (autoPresets.length) { | ||
presetFilePath = this.resolve(autoPresets[0]); | ||
this._toolsDir = new file_path_1.default(path_1.default.dirname(this.resolve(autoPresets[0] + '/package.json'))); | ||
} | ||
else { | ||
// If no preset was found, use the default one | ||
presetFilePath = require.resolve('liferay-npm-bundler-preset-standard'); | ||
this._toolsDir = new file_path_1.default(path_1.default.dirname(require.resolve('liferay-npm-bundler-preset-standard/package.json'))); | ||
} | ||
return presetFilePath; | ||
return autopresets.length ? autopresets[0] : null; | ||
} | ||
@@ -326,20 +323,39 @@ _loadNpmbundlerrc() { | ||
let presetFilePath; | ||
if (config.preset === undefined) { | ||
presetFilePath = this._loadDefaultPreset(); | ||
const autopreset = this._getAutopreset(); | ||
if (config.preset === undefined && autopreset) { | ||
// If an autopreset is found and none is configured, use it | ||
this._presetInfo = { | ||
isAutopreset: true, | ||
name: autopreset, | ||
}; | ||
this._toolsDir = new file_path_1.default(path_1.default.dirname(this.resolve(`${autopreset}/package.json`))); | ||
presetFilePath = this.resolve(autopreset); | ||
} | ||
else if (config.preset === undefined) { | ||
// If no preset was found, use the default one | ||
this._presetInfo = { | ||
isAutopreset: false, | ||
name: 'liferay-npm-bundler-preset-standard', | ||
}; | ||
this._toolsDir = new file_path_1.default(path_1.default.dirname(require.resolve('liferay-npm-bundler-preset-standard/package.json'))); | ||
presetFilePath = require.resolve('liferay-npm-bundler-preset-standard'); | ||
} | ||
else if (config.preset === '' || config.preset === false) { | ||
// don't load preset | ||
this._presetInfo = undefined; | ||
} | ||
else { | ||
presetFilePath = resolve_1.default.sync(config.preset, { | ||
basedir: this.dir.asNative, | ||
}); | ||
// If a preset is configured, use it | ||
this._presetInfo = { | ||
isAutopreset: false, | ||
name: config.preset, | ||
}; | ||
const { pkgName, scope } = modules_1.splitModuleName(config.preset); | ||
const presetPkgJsonFilePath = resolve_1.default.sync(scope | ||
const presetPkgJsonFilePath = this.resolve(scope | ||
? `${scope}/${pkgName}/package.json` | ||
: `${pkgName}/package.json`, { | ||
basedir: this.dir.asNative, | ||
}); | ||
: `${pkgName}/package.json`); | ||
this._toolsDir = new file_path_1.default(path_1.default.dirname(presetPkgJsonFilePath)); | ||
presetFilePath = this.resolve(config.preset); | ||
} | ||
// Load preset configuration | ||
if (presetFilePath) { | ||
@@ -346,0 +362,0 @@ const originalConfig = { ...config }; |
@@ -7,3 +7,3 @@ { | ||
"escape-string-regexp": "^2.0.0", | ||
"liferay-npm-bundler-preset-standard": "2.25.0", | ||
"liferay-npm-bundler-preset-standard": "2.26.0", | ||
"merge": "^1.2.1", | ||
@@ -26,4 +26,4 @@ "properties": "^1.2.1", | ||
}, | ||
"version": "2.25.0", | ||
"gitHead": "5501d9e5c15145cfd4d9d45bcc26fff1fd3420ba" | ||
"version": "2.26.0", | ||
"gitHead": "1b968d796b07da761cd71157562f88d07db31ace" | ||
} |
@@ -13,5 +13,5 @@ /** | ||
//////////////////////////////////////////////////////////////////////////////// | ||
// Tests by property | ||
//////////////////////////////////////////////////////////////////////////////// | ||
/** | ||
* Tests by property | ||
*/ | ||
@@ -589,5 +589,5 @@ describe('project', () => { | ||
//////////////////////////////////////////////////////////////////////////////// | ||
// Tests by orthogonal features | ||
//////////////////////////////////////////////////////////////////////////////// | ||
/** | ||
* Tests by orthogonal features | ||
*/ | ||
@@ -594,0 +594,0 @@ describe('default features are detected', () => { |
@@ -28,2 +28,8 @@ /** | ||
/** Information on the preset being used */ | ||
export interface PresetInfo { | ||
name: string; | ||
isAutopreset: boolean; | ||
} | ||
/** | ||
@@ -182,2 +188,9 @@ * Describes a standard JS Toolkit project. | ||
/** | ||
* Get information about the preset in use | ||
*/ | ||
get presetInfo(): PresetInfo | undefined { | ||
return this._presetInfo; | ||
} | ||
/** | ||
* Get all available information about versions of plugins and presets used | ||
@@ -298,3 +311,3 @@ * for the build. | ||
*/ | ||
resolve(moduleName: string): any { | ||
resolve(moduleName: string): string { | ||
return resolveModule.sync(moduleName, { | ||
@@ -357,3 +370,3 @@ basedir: this.dir.asNative, | ||
*/ | ||
toolResolve(moduleName: string): any { | ||
toolResolve(moduleName: string): string { | ||
try { | ||
@@ -369,15 +382,23 @@ return resolveModule.sync(moduleName, { | ||
_findAutopresets(): string[] { | ||
_getAutopreset(): string | null { | ||
const {dependencies = {}, devDependencies = {}} = this._pkgJson; | ||
return Object.keys({ | ||
const autopresets = Object.keys({ | ||
...dependencies, | ||
...devDependencies, | ||
}).reduce((autoPresets, pkgName) => { | ||
}).reduce((autopresets, pkgName) => { | ||
try { | ||
const {dependencies} = this.require(pkgName + '/package.json'); | ||
if (dependencies && dependencies['liferay-npm-bundler']) { | ||
autoPresets.push(pkgName); | ||
if (!dependencies || !dependencies['liferay-npm-bundler']) { | ||
return autopresets; | ||
} | ||
const mainModulePath = this.resolve(pkgName); | ||
if (!mainModulePath.toLowerCase().endsWith('.json')) { | ||
return autopresets; | ||
} | ||
autopresets.push(pkgName); | ||
} | ||
@@ -390,16 +411,9 @@ catch (err) { | ||
return autoPresets; | ||
return autopresets; | ||
}, []); | ||
} | ||
_loadDefaultPreset(): string { | ||
let presetFilePath; | ||
const autoPresets = this._findAutopresets(); | ||
if (autoPresets.length > 1) { | ||
if (autopresets.length > 1) { | ||
throw new Error( | ||
'Multiple autopreset dependencies found in project (' + | ||
autoPresets + | ||
'): please remove the invalid ones or ' + | ||
'Multiple autopreset dependencies found in project ' + | ||
`(${autopresets}): please remove the invalid ones or ` + | ||
'explicitly define the preset to be used in the ' + | ||
@@ -409,16 +423,42 @@ '.npmbundlerrc file' | ||
} | ||
else if (autoPresets.length) { | ||
presetFilePath = this.resolve(autoPresets[0]); | ||
return autopresets.length ? autopresets[0] : null; | ||
} | ||
_loadNpmbundlerrc(): void { | ||
const npmbundlerrcPath = this._configFile.asNative; | ||
const config = fs.existsSync(npmbundlerrcPath) | ||
? readJsonSync(npmbundlerrcPath) | ||
: {}; | ||
// Apply preset if necessary | ||
let presetFilePath: string; | ||
const autopreset = this._getAutopreset(); | ||
if (config.preset === undefined && autopreset) { | ||
// If an autopreset is found and none is configured, use it | ||
this._presetInfo = { | ||
isAutopreset: true, | ||
name: autopreset, | ||
}; | ||
this._toolsDir = new FilePath( | ||
path.dirname(this.resolve(autoPresets[0] + '/package.json')) | ||
path.dirname(this.resolve(`${autopreset}/package.json`)) | ||
); | ||
presetFilePath = this.resolve(autopreset); | ||
} | ||
else { | ||
else if (config.preset === undefined) { | ||
// If no preset was found, use the default one | ||
presetFilePath = require.resolve( | ||
'liferay-npm-bundler-preset-standard' | ||
); | ||
this._presetInfo = { | ||
isAutopreset: false, | ||
name: 'liferay-npm-bundler-preset-standard', | ||
}; | ||
@@ -432,20 +472,6 @@ this._toolsDir = new FilePath( | ||
); | ||
} | ||
return presetFilePath; | ||
} | ||
_loadNpmbundlerrc(): void { | ||
const npmbundlerrcPath = this._configFile.asNative; | ||
const config = fs.existsSync(npmbundlerrcPath) | ||
? readJsonSync(npmbundlerrcPath) | ||
: {}; | ||
// Apply preset if necessary | ||
let presetFilePath; | ||
if (config.preset === undefined) { | ||
presetFilePath = this._loadDefaultPreset(); | ||
presetFilePath = require.resolve( | ||
'liferay-npm-bundler-preset-standard' | ||
); | ||
} | ||
@@ -456,22 +482,28 @@ else if (config.preset === '' || config.preset === false) { | ||
this._presetInfo = undefined; | ||
} | ||
else { | ||
presetFilePath = resolveModule.sync(config.preset, { | ||
basedir: this.dir.asNative, | ||
}); | ||
// If a preset is configured, use it | ||
this._presetInfo = { | ||
isAutopreset: false, | ||
name: config.preset, | ||
}; | ||
const {pkgName, scope} = splitModuleName(config.preset); | ||
const presetPkgJsonFilePath = resolveModule.sync( | ||
const presetPkgJsonFilePath = this.resolve( | ||
scope | ||
? `${scope}/${pkgName}/package.json` | ||
: `${pkgName}/package.json`, | ||
{ | ||
basedir: this.dir.asNative, | ||
} | ||
: `${pkgName}/package.json` | ||
); | ||
this._toolsDir = new FilePath(path.dirname(presetPkgJsonFilePath)); | ||
presetFilePath = this.resolve(config.preset); | ||
} | ||
// Load preset configuration | ||
if (presetFilePath) { | ||
@@ -507,2 +539,5 @@ const originalConfig = {...config}; | ||
/** Info about preset in use */ | ||
private _presetInfo: PresetInfo; | ||
/** Absolute path to project directory */ | ||
@@ -509,0 +544,0 @@ private _projectDir: FilePath; |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
314572
9709
+ Addedbabel-plugin-add-module-metadata@2.26.0(transitive)
+ Addedbabel-plugin-alias-modules@2.26.0(transitive)
+ Addedbabel-plugin-name-amd-modules@2.26.0(transitive)
+ Addedbabel-plugin-namespace-amd-define@2.26.0(transitive)
+ Addedbabel-plugin-namespace-modules@2.26.0(transitive)
+ Addedbabel-plugin-normalize-requires@2.26.0(transitive)
+ Addedbabel-plugin-wrap-modules-amd@2.26.0(transitive)
+ Addedbabel-preset-liferay-standard@2.26.0(transitive)
+ Addedliferay-npm-bundler-plugin-exclude-imports@2.26.0(transitive)
+ Addedliferay-npm-bundler-plugin-inject-imports-dependencies@2.26.0(transitive)
+ Addedliferay-npm-bundler-plugin-inject-peer-dependencies@2.26.0(transitive)
+ Addedliferay-npm-bundler-plugin-namespace-packages@2.26.0(transitive)
+ Addedliferay-npm-bundler-plugin-replace-browser-modules@2.26.0(transitive)
+ Addedliferay-npm-bundler-plugin-resolve-linked-dependencies@2.26.0(transitive)
+ Addedliferay-npm-bundler-preset-standard@2.26.0(transitive)
- Removedbabel-plugin-add-module-metadata@2.25.0(transitive)
- Removedbabel-plugin-alias-modules@2.25.0(transitive)
- Removedbabel-plugin-name-amd-modules@2.25.0(transitive)
- Removedbabel-plugin-namespace-amd-define@2.25.0(transitive)
- Removedbabel-plugin-namespace-modules@2.25.0(transitive)
- Removedbabel-plugin-normalize-requires@2.25.0(transitive)
- Removedbabel-plugin-wrap-modules-amd@2.25.0(transitive)
- Removedbabel-preset-liferay-standard@2.25.0(transitive)
- Removedliferay-npm-bundler-plugin-exclude-imports@2.25.0(transitive)
- Removedliferay-npm-bundler-plugin-inject-imports-dependencies@2.25.0(transitive)
- Removedliferay-npm-bundler-plugin-inject-peer-dependencies@2.25.0(transitive)
- Removedliferay-npm-bundler-plugin-namespace-packages@2.25.0(transitive)
- Removedliferay-npm-bundler-plugin-replace-browser-modules@2.25.0(transitive)
- Removedliferay-npm-bundler-plugin-resolve-linked-dependencies@2.25.0(transitive)
- Removedliferay-npm-bundler-preset-standard@2.25.0(transitive)