liferay-npm-build-tools-common
Advanced tools
Comparing version 2.24.3 to 2.25.0
@@ -127,2 +127,4 @@ /** | ||
toolResolve(moduleName: string): any; | ||
_findAutopresets(): string[]; | ||
_loadDefaultPreset(): string; | ||
_loadNpmbundlerrc(): void; | ||
@@ -129,0 +131,0 @@ _loadPkgJson(): void; |
@@ -277,2 +277,41 @@ "use strict"; | ||
} | ||
_findAutopresets() { | ||
const { dependencies = {}, devDependencies = {} } = this._pkgJson; | ||
return Object.keys({ | ||
...dependencies, | ||
...devDependencies, | ||
}).reduce((autoPresets, pkgName) => { | ||
try { | ||
const { dependencies } = this.require(pkgName + '/package.json'); | ||
if (dependencies && dependencies['liferay-npm-bundler']) { | ||
autoPresets.push(pkgName); | ||
} | ||
} | ||
catch (err) { | ||
// ignore | ||
} | ||
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 ' + | ||
'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; | ||
} | ||
_loadNpmbundlerrc() { | ||
@@ -286,4 +325,3 @@ const npmbundlerrcPath = this._configFile.asNative; | ||
if (config.preset === undefined) { | ||
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'))); | ||
presetFilePath = this._loadDefaultPreset(); | ||
} | ||
@@ -290,0 +328,0 @@ else if (config.preset === '' || config.preset === false) { |
@@ -86,5 +86,9 @@ "use strict"; | ||
if (this._outputFilename === undefined) { | ||
this._outputFilename = dot_prop_1.default.get(npmbundlerrc, 'create-jar.output-filename', this.supported | ||
? pkgJson['name'] + '-' + pkgJson['version'] + '.jar' | ||
: undefined); | ||
let defaultValue; | ||
if (this.supported) { | ||
defaultValue = | ||
pkgJson['name'] + '-' + pkgJson['version'] + '.jar'; | ||
defaultValue = defaultValue.replace(/\//g, '_'); | ||
} | ||
this._outputFilename = dot_prop_1.default.get(npmbundlerrc, 'create-jar.output-filename', defaultValue); | ||
} | ||
@@ -91,0 +95,0 @@ return this._outputFilename; |
@@ -7,3 +7,3 @@ { | ||
"escape-string-regexp": "^2.0.0", | ||
"liferay-npm-bundler-preset-standard": "2.24.3", | ||
"liferay-npm-bundler-preset-standard": "2.25.0", | ||
"merge": "^1.2.1", | ||
@@ -26,3 +26,4 @@ "properties": "^1.2.1", | ||
}, | ||
"version": "2.24.3" | ||
"version": "2.25.0", | ||
"gitHead": "5501d9e5c15145cfd4d9d45bcc26fff1fd3420ba" | ||
} |
@@ -161,2 +161,10 @@ /** | ||
}); | ||
it('returns a correct file name for scoped packages', () => { | ||
const project = new Project( | ||
path.join(__dirname, '__fixtures__', 'project', 'scoped') | ||
); | ||
expect(project.jar.outputFilename).toBe('@scoped_project-1.0.0.jar'); | ||
}); | ||
}); | ||
@@ -768,2 +776,39 @@ | ||
describe('handles autopresets', () => { | ||
it('loads autopresets', () => { | ||
const project = new Project( | ||
path.join(__dirname, '__fixtures__', 'project', 'with-autopreset') | ||
); | ||
expect(project.buildDir.asPosix).toBe('./autopreset-build'); | ||
}); | ||
it('fails on multiple autopresets', () => { | ||
expect( | ||
() => | ||
new Project( | ||
path.join( | ||
__dirname, | ||
'__fixtures__', | ||
'project', | ||
'with-two-autopresets' | ||
) | ||
) | ||
).toThrowError(/Multiple autopreset.*autopreset.*autopreset2.*/); | ||
}); | ||
it('ignores autopresets on explicitly configured preset', () => { | ||
const project = new Project( | ||
path.join( | ||
__dirname, | ||
'__fixtures__', | ||
'project', | ||
'with-ignored-autopreset' | ||
) | ||
); | ||
expect(project.buildDir.asPosix).toBe('./preset-build'); | ||
}); | ||
}); | ||
describe('loads plugins as modules (as opposed to packages)', () => { | ||
@@ -770,0 +815,0 @@ let project; |
@@ -365,14 +365,51 @@ /** | ||
_loadNpmbundlerrc(): void { | ||
const npmbundlerrcPath = this._configFile.asNative; | ||
_findAutopresets(): string[] { | ||
const {dependencies = {}, devDependencies = {}} = this._pkgJson; | ||
const config = fs.existsSync(npmbundlerrcPath) | ||
? readJsonSync(npmbundlerrcPath) | ||
: {}; | ||
return Object.keys({ | ||
...dependencies, | ||
...devDependencies, | ||
}).reduce((autoPresets, pkgName) => { | ||
try { | ||
const {dependencies} = this.require(pkgName + '/package.json'); | ||
// Apply preset if necessary | ||
if (dependencies && dependencies['liferay-npm-bundler']) { | ||
autoPresets.push(pkgName); | ||
} | ||
} | ||
catch (err) { | ||
// ignore | ||
} | ||
return autoPresets; | ||
}, []); | ||
} | ||
_loadDefaultPreset(): string { | ||
let presetFilePath; | ||
if (config.preset === undefined) { | ||
const autoPresets = this._findAutopresets(); | ||
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 FilePath( | ||
path.dirname(this.resolve(autoPresets[0] + '/package.json')) | ||
); | ||
} | ||
else { | ||
// If no preset was found, use the default one | ||
presetFilePath = require.resolve( | ||
@@ -390,2 +427,20 @@ 'liferay-npm-bundler-preset-standard' | ||
} | ||
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(); | ||
} | ||
else if (config.preset === '' || config.preset === false) { | ||
@@ -442,3 +497,3 @@ | ||
private _npmbundlerrc: object; | ||
private _pkgJson: object; | ||
private _pkgJson: {dependencies: object; devDependencies: object}; | ||
private _pkgManager: PkgManager; | ||
@@ -445,0 +500,0 @@ |
@@ -128,8 +128,15 @@ /** | ||
if (this._outputFilename === undefined) { | ||
let defaultValue; | ||
if (this.supported) { | ||
defaultValue = | ||
pkgJson['name'] + '-' + pkgJson['version'] + '.jar'; | ||
defaultValue = defaultValue.replace(/\//g, '_'); | ||
} | ||
this._outputFilename = prop.get( | ||
npmbundlerrc, | ||
'create-jar.output-filename', | ||
this.supported | ||
? pkgJson['name'] + '-' + pkgJson['version'] + '.jar' | ||
: undefined | ||
defaultValue | ||
); | ||
@@ -136,0 +143,0 @@ } |
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
313157
227
9661
+ Addedbabel-plugin-add-module-metadata@2.25.0(transitive)
+ Addedbabel-plugin-alias-modules@2.25.0(transitive)
+ Addedbabel-plugin-name-amd-modules@2.25.0(transitive)
+ Addedbabel-plugin-namespace-amd-define@2.25.0(transitive)
+ Addedbabel-plugin-namespace-modules@2.25.0(transitive)
+ Addedbabel-plugin-normalize-requires@2.25.0(transitive)
+ Addedbabel-plugin-syntax-object-rest-spread@6.13.0(transitive)
+ Addedbabel-plugin-transform-object-rest-spread@6.26.0(transitive)
+ Addedbabel-plugin-wrap-modules-amd@2.25.0(transitive)
+ Addedbabel-preset-liferay-standard@2.25.0(transitive)
+ Addedliferay-npm-bundler-plugin-exclude-imports@2.25.0(transitive)
+ Addedliferay-npm-bundler-plugin-inject-imports-dependencies@2.25.0(transitive)
+ Addedliferay-npm-bundler-plugin-inject-peer-dependencies@2.25.0(transitive)
+ Addedliferay-npm-bundler-plugin-namespace-packages@2.25.0(transitive)
+ Addedliferay-npm-bundler-plugin-replace-browser-modules@2.25.0(transitive)
+ Addedliferay-npm-bundler-plugin-resolve-linked-dependencies@2.25.0(transitive)
+ Addedliferay-npm-bundler-preset-standard@2.25.0(transitive)
- Removedbabel-plugin-add-module-metadata@2.24.3(transitive)
- Removedbabel-plugin-alias-modules@2.24.3(transitive)
- Removedbabel-plugin-name-amd-modules@2.24.3(transitive)
- Removedbabel-plugin-namespace-amd-define@2.24.3(transitive)
- Removedbabel-plugin-namespace-modules@2.24.3(transitive)
- Removedbabel-plugin-normalize-requires@2.24.3(transitive)
- Removedbabel-plugin-wrap-modules-amd@2.24.3(transitive)
- Removedbabel-preset-liferay-standard@2.24.3(transitive)
- Removedliferay-npm-bundler-plugin-exclude-imports@2.24.3(transitive)
- Removedliferay-npm-bundler-plugin-inject-imports-dependencies@2.24.3(transitive)
- Removedliferay-npm-bundler-plugin-inject-peer-dependencies@2.24.3(transitive)
- Removedliferay-npm-bundler-plugin-namespace-packages@2.24.3(transitive)
- Removedliferay-npm-bundler-plugin-replace-browser-modules@2.24.3(transitive)
- Removedliferay-npm-bundler-plugin-resolve-linked-dependencies@2.24.3(transitive)
- Removedliferay-npm-bundler-preset-standard@2.24.3(transitive)