diff --git a/packages/micropack/src/cli.mjs b/packages/micropack/src/cli.mjs index 445c816..9a6c985 100755 --- a/packages/micropack/src/cli.mjs +++ b/packages/micropack/src/cli.mjs @@ -49,8 +49,9 @@ program 'Files .css will be parsed as modules (default: null)', DEFAULT_OPTIONS.cssModule ) - .option('--timestamp', 'Add timestamp to beging of file', false) + .option('--no-timestamp', 'Add timestamp to beging of file', true) .action(async (opts) => { + console.log(opts) try { await micropack(opts); } catch (e) { @@ -69,7 +70,7 @@ program.on('--help', function () { export function run(argv) { setupExceptionHandler(); + console.log(argv) program.parse(argv); } - run(process.argv); diff --git a/packages/micropack/src/utils/cmd.mjs b/packages/micropack/src/utils/cmd.mjs index 5e162f1..928f381 100644 --- a/packages/micropack/src/utils/cmd.mjs +++ b/packages/micropack/src/utils/cmd.mjs @@ -8,5 +8,7 @@ export const collectDict = (vals, acc) => ({ return acc; }, {}), }); -export const collectList = (vals, acc) => [...acc, ...vals.split(',')]; +export const collectList = (vals, acc=[]) => { + return [...acc, ...vals.split(',')]; +} export const increaseVerbose = (_, acc) => (acc += 1); diff --git a/packages/micropack/test/__snapshots__/index.test.mjs.snap b/packages/micropack/test/__snapshots__/index.test.mjs.snap index 378e6c7..41b789f 100644 --- a/packages/micropack/test/__snapshots__/index.test.mjs.snap +++ b/packages/micropack/test/__snapshots__/index.test.mjs.snap @@ -37,6 +37,7 @@ css-module index.mjs package.json src + declarations.d.ts index.ts main.css main.module.css diff --git a/packages/micropack/test/fixtures/css-module/src/declarations.d.ts b/packages/micropack/test/fixtures/css-module/src/declarations.d.ts new file mode 100644 index 0000000..35306c6 --- /dev/null +++ b/packages/micropack/test/fixtures/css-module/src/declarations.d.ts @@ -0,0 +1 @@ +declare module '*.css'; diff --git a/packages/micropack/test/index.test.mjs b/packages/micropack/test/index.test.mjs index 708f6cf..31eeba9 100644 --- a/packages/micropack/test/index.test.mjs +++ b/packages/micropack/test/index.test.mjs @@ -8,7 +8,6 @@ import { buildFixture, printDirTree, findAllFiles } from './utils.mjs'; chai.use(jestSnapshotPlugin()); - const __dirname = url.fileURLToPath(new URL('.', import.meta.url)); const FIXTURES_DIR = `${__dirname}fixtures`; @@ -41,6 +40,6 @@ describe('fixtures', () => { for(const [name, filePath] of files) { expect(readFileSync(filePath, { encoding: 'utf8'})).toMatchSnapshot(`dist/${name}`); } - }); + }).timeout(5000); }); }); diff --git a/packages/micropack/test/setup.mjs b/packages/micropack/test/setup.mjs deleted file mode 100644 index e69de29..0000000 diff --git a/packages/micropack/test/utils.mjs b/packages/micropack/test/utils.mjs index 7026d73..c565904 100644 --- a/packages/micropack/test/utils.mjs +++ b/packages/micropack/test/utils.mjs @@ -1,10 +1,19 @@ +import {readFileSync} from 'fs'; +import Path from 'node:path'; +import Url from 'node:url'; import {execaSync} from 'execa'; import dirTree from 'directory-tree'; +const __dirname = Url.fileURLToPath(new URL('.', import.meta.url)); +const mainScript = Path.resolve(__dirname, '../src/cli.mjs'); + export function buildFixture(path) { + const build = JSON.parse(readFileSync(Path.join(path, 'package.json')))['scripts']['build']; + const buildParams = build.split(' ').slice(1); + const params = [mainScript, ...buildParams, '--no-timestamp']; try { - const result = execaSync('npm', ['run', 'build'], {cwd: path}); + const result = execaSync('node', params, {cwd: path}); if (result.stderr) { return result.stderr; }