Files
Jeffrey PosnickandGitHub 7d4c4434a4 Enable prettier (#2929)
* Deps and config

* Prettier output

* Update hardcoded file sizes

* More file size updates
2021-08-26 14:57:20 -07:00

38 lines
1.1 KiB
JavaScript

/*
Copyright 2018 Google LLC
Use of this source code is governed by an MIT-style
license that can be found in the LICENSE file or at
https://opensource.org/licenses/MIT.
*/
const fs = require('fs-extra');
const path = require('path');
const pkgPathToName = require('./pkg-path-to-name');
const getDetails = (packagePath) => {
// Read file from filesystem to avoid require caching
const packageJsonPath = path.join(packagePath, 'package.json');
const pkgJson = fs.readJSONSync(packageJsonPath);
const name = pkgPathToName(packagePath).replace('workbox-', '');
return ['workbox', name, pkgJson.version].join(':');
};
module.exports = async (packagePath) => {
const versionString = `try{self['${getDetails(
packagePath,
)}']&&_()}catch(e){}`;
if (await fs.pathExists(path.join(packagePath, 'src', 'index.ts'))) {
const tsVersionString = `// @ts-ignore\n${versionString}`;
await fs.writeFile(
path.join(packagePath, 'src', '_version.ts'),
tsVersionString,
);
}
const mjsVersionString = `${versionString}// eslint-disable-line`;
return fs.writeFile(path.join(packagePath, '_version.mjs'), mjsVersionString);
};