Skip to content

Commit

Permalink
Switch to ESM
Browse files Browse the repository at this point in the history
  • Loading branch information
XhmikosR committed Dec 7, 2021
1 parent e524abe commit e4b8324
Show file tree
Hide file tree
Showing 8 changed files with 131 additions and 209 deletions.
6 changes: 3 additions & 3 deletions .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
"node": true
},
"parserOptions": {
"ecmaVersion": 2019
"ecmaVersion": 2020,
"sourceType": "module"
},
"extends": "eslint:recommended",
"rules": {
Expand All @@ -15,7 +16,6 @@
"object": true,
"array": false
}
],
"strict": "error"
]
}
}
7 changes: 3 additions & 4 deletions cli.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
#!/usr/bin/env node

'use strict';

const { spawn } = require('child_process');
const hugo = require('.');
import { spawn } from 'node:child_process';
import process from 'node:process';
import hugo from './index.js';

const input = process.argv.slice(2);

Expand Down
5 changes: 3 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
'use strict';
import process from 'node:process';
import lib from './lib/index.js';

module.exports = require('./lib')(process.cwd()).path();
export default lib(process.cwd()).path();
23 changes: 14 additions & 9 deletions lib/index.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
'use strict';
import fs from 'node:fs';
import path from 'node:path';
import process from 'node:process';
import { fileURLToPath } from 'node:url';
import BinWrapper from 'bin-wrapper';
import { packageConfigSync } from 'pkg-conf';

const path = require('path');
const BinWrapper = require('bin-wrapper');
const pkgConf = require('pkg-conf');
const { hugoVersion } = require('../package.json');
const { hugoVersion } = JSON.parse(fs.readFileSync(new URL('../package.json', import.meta.url)));

const baseUrl = `https://github.com/gohugoio/hugo/releases/download/v${hugoVersion}/`;
const destDir = path.join(__dirname, '../vendor/');
const destDir = path.join(fileURLToPath(new URL('../vendor', import.meta.url)));
const binName = process.platform === 'win32' ? 'hugo.exe' : 'hugo';

const extendedBin = new BinWrapper()
Expand Down Expand Up @@ -44,8 +46,11 @@ const normalBin = new BinWrapper()
.dest(destDir)
.use(binName);

module.exports = projectRoot => {
const config = pkgConf.sync('hugo-bin', { cwd: projectRoot });
function main(projectRoot) {
const config = packageConfigSync('hugo-bin', { cwd: projectRoot });
const extended = (process.env.HUGO_BIN_BUILD_TAGS || process.env.npm_config_hugo_bin_build_tags || config.buildTags) === 'extended';

return extended ? extendedBin : normalBin;
};
}

export default main;
7 changes: 3 additions & 4 deletions lib/install.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
'use strict';

const path = require('path');
const bin = require('.');
import path from 'node:path';
import process from 'node:process';
import bin from './index.js';

function getProjectRoot() {
// `projectRoot` on postinstall could be INIT_CWD introduced in npm >= 5.4
Expand Down
Loading

0 comments on commit e4b8324

Please sign in to comment.