Skip to content

Commit

Permalink
chore: fix prettier
Browse files Browse the repository at this point in the history
  • Loading branch information
moroine committed Mar 24, 2022
1 parent 16dd6ff commit 8dec6d1
Showing 1 changed file with 83 additions and 96 deletions.
179 changes: 83 additions & 96 deletions lib/packExternalModules.js
Original file line number Diff line number Diff line change
Expand Up @@ -300,26 +300,26 @@ module.exports = {
});
}

// (1) Generate dependency composition
const compositeModules = _.uniq(
_.flatMap(stats.stats, compileStats => {
const externalModules = _.concat(
compileStats.externalModules,
_.map(packageForceIncludes, whitelistedPackage => ({
external: whitelistedPackage
}))
);
return getProdModules.call(
this,
externalModules,
packagePath,
nodeModulesRelativeDir,
dependencyGraph,
packageForceExcludes
);
})
);
removeExcludedModules.call(this, compositeModules, packageForceExcludes, true);
// (1) Generate dependency composition
const compositeModules = _.uniq(
_.flatMap(stats.stats, compileStats => {
const externalModules = _.concat(
compileStats.externalModules,
_.map(packageForceIncludes, whitelistedPackage => ({
external: whitelistedPackage
}))
);
return getProdModules.call(
this,
externalModules,
packagePath,
nodeModulesRelativeDir,
dependencyGraph,
packageForceExcludes
);
})
);
removeExcludedModules.call(this, compositeModules, packageForceExcludes, true);

if (_.isEmpty(compositeModules)) {
// The compiled code does not reference any external modules at all
Expand All @@ -331,24 +331,24 @@ module.exports = {
return BbPromise.resolve();
}

// (1.a) Install all needed modules
const compositeModulePath = path.join(this.webpackOutputPath, 'dependencies');
const compositePackageJson = path.join(compositeModulePath, 'package.json');

// (1.a.1) Create a package.json
const compositePackage = _.defaults(
{
name: this.serverless.service.service,
version: '1.0.0',
description: `Packaged externals for ${this.serverless.service.service}`,
private: true,
scripts: packageScripts
},
packageSections
);
const relPath = path.relative(compositeModulePath, path.dirname(packageJsonPath));
addModulesToPackageJson(compositeModules, compositePackage, relPath);
this.serverless.utils.writeFileSync(compositePackageJson, JSON.stringify(compositePackage, null, 2));
// (1.a) Install all needed modules
const compositeModulePath = path.join(this.webpackOutputPath, 'dependencies');
const compositePackageJson = path.join(compositeModulePath, 'package.json');

// (1.a.1) Create a package.json
const compositePackage = _.defaults(
{
name: this.serverless.service.service,
version: '1.0.0',
description: `Packaged externals for ${this.serverless.service.service}`,
private: true,
scripts: packageScripts
},
packageSections
);
const relPath = path.relative(compositeModulePath, path.dirname(packageJsonPath));
addModulesToPackageJson(compositeModules, compositePackage, relPath);
this.serverless.utils.writeFileSync(compositePackageJson, JSON.stringify(compositePackage, null, 2));

// (1.a.2) Copy package-lock.json if it exists, to prevent unwanted upgrades
const packageLockPath = path.join(path.dirname(packageJsonPath), packager.lockfileName);
Expand Down Expand Up @@ -413,65 +413,52 @@ module.exports = {
.mapSeries(compileStats => {
const modulePath = compileStats.outputPath;

// Create package.json
const modulePackageJson = path.join(modulePath, 'package.json');
const modulePackage = _.defaults(
{
name: this.serverless.service.service,
version: '1.0.0',
description: `Packaged externals for ${this.serverless.service.service}`,
private: true,
scripts: packageScripts,
dependencies: {}
},
packageSections
);
const prodModules = getProdModules.call(
this,
_.concat(
compileStats.externalModules,
_.map(packageForceIncludes, whitelistedPackage => ({
external: whitelistedPackage
}))
),
packagePath,
nodeModulesRelativeDir,
dependencyGraph,
packageForceExcludes
);
removeExcludedModules.call(this, prodModules, packageForceExcludes);
const relPath = path.relative(modulePath, path.dirname(packageJsonPath));
addModulesToPackageJson(prodModules, modulePackage, relPath);
this.serverless.utils.writeFileSync(modulePackageJson, JSON.stringify(modulePackage, null, 2));

// GOOGLE: Copy modules only if not google-cloud-functions
// GCF Auto installs the package json
if (_.get(this.serverless, 'service.provider.name') === 'google') {
return BbPromise.resolve();
}

const startCopy = _.now();
return BbPromise.try(() => {
// Only copy dependency modules if demanded by packager
if (packager.mustCopyModules) {
return BbPromise.fromCallback(callback =>
fse.copy(
path.join(compositeModulePath, 'node_modules'),
path.join(modulePath, 'node_modules'),
callback
)
);
// Create package.json
const modulePackageJson = path.join(modulePath, 'package.json');
const modulePackage = _.defaults(
{
name: this.serverless.service.service,
version: '1.0.0',
description: `Packaged externals for ${this.serverless.service.service}`,
private: true,
scripts: packageScripts,
dependencies: {}
},
packageSections
);
const prodModules = getProdModules.call(
this,
_.concat(
compileStats.externalModules,
_.map(packageForceIncludes, whitelistedPackage => ({
external: whitelistedPackage
}))
),
packagePath,
nodeModulesRelativeDir,
dependencyGraph,
packageForceExcludes
);
removeExcludedModules.call(this, prodModules, packageForceExcludes);
const relPath = path.relative(modulePath, path.dirname(packageJsonPath));
addModulesToPackageJson(prodModules, modulePackage, relPath);
this.serverless.utils.writeFileSync(modulePackageJson, JSON.stringify(modulePackage, null, 2));

// GOOGLE: Copy modules only if not google-cloud-functions
// GCF Auto installs the package json
if (_.get(this.serverless, 'service.provider.name') === 'google') {
return BbPromise.resolve();
}
return BbPromise.resolve();
})
.then(() =>
hasPackageLock
? BbPromise.fromCallback(callback =>
fse.copy(
path.join(compositeModulePath, packager.lockfileName),
path.join(modulePath, packager.lockfileName),
callback
)

const startCopy = _.now();
return BbPromise.try(() => {
// Only copy dependency modules if demanded by packager
if (packager.mustCopyModules) {
return BbPromise.fromCallback(callback =>
fse.copy(
path.join(compositeModulePath, 'node_modules'),
path.join(modulePath, 'node_modules'),
callback
)
: BbPromise.resolve()
)
Expand Down

0 comments on commit 8dec6d1

Please sign in to comment.