am-compiler
raw JSON → 1.0.31 verified Fri May 01 auth: no javascript
am-compiler is a CoffeeScript-based build tool that compiles multiple targets (electron, node, browser) from CoffeeScript source files. As of version 1.0.31, it appears to be a niche package with minimal documentation and no recent updates. It relies on fs-extra for reading JSON and child_process for executing commands. Key differentiators include a custom class extending a base compiler and targeted entry points for electron, node, and browser builds. However, it lacks comprehensive documentation and may be considered experimental or specific to certain workflows.
Common errors
error TypeError: Compiler is not a constructor ↓
cause Importing the module incorrectly or using an older version where export was different.
fix
Ensure you are using version >=1.0.25 and use const Compiler = require('am-compiler').
error Cannot find module 'am-compiler' ↓
cause Package not installed or not in node_modules.
fix
Run npm install am-compiler --save
error fse.readJsonSync is not a function ↓
cause fs-extra not installed or not required.
fix
Install fs-extra: npm install fs-extra --save and require it: const fse = require('fs-extra');
Warnings
gotcha The start method must be called after instantiation; it is not automatically called. ↓
fix Create an instance and call .start() explicitly.
gotcha callback expects super.callback(err, stats) to be called; failing to do so may break chain. ↓
fix Always call super.callback(err, stats) in overridden callback.
breaking In versions prior to 1.0.25, the class name was AmCompilerExport and the module exported differently. ↓
fix Use const Compiler = require('am-compiler') for all versions >=1.0.25.
deprecated The package is no longer actively maintained and may break with newer Node.js versions. ↓
fix Consider migrating to a more modern build tool like Webpack or Rollup.
Install
npm install am-compiler yarn add am-compiler pnpm add am-compiler Imports
- Compiler wrong
import Compiler from 'am-compiler'correctconst Compiler = require('am-compiler') - AmCompiler wrong
import { AmCompiler } from 'am-compiler'correctconst AmCompiler = require('am-compiler') - Class extension wrong
class MyCompiler extends require('am-compiler').Compiler { ... }correctclass MyCompiler extends Compiler { ... }
Quickstart
const fse = require('fs-extra');
const Compiler = require('am-compiler');
class AmCompiler extends Compiler {
constructor() {
super();
this.checkNum = 0;
}
electronStart() {
const cmd = fse.readJsonSync('package.json').scripts.electron;
require('child_process').exec(cmd);
}
callback(err, stats) {
super.callback(err, stats);
if (err) {
console.log(err);
return;
}
this.checkNum++;
if (this.checkNum === 3) {
this.electronStart();
}
}
start() {
this.electronOption.entry = {
'electron/.build/start': './electron/test/start.coffee',
'app/.build/preload': './app/test/preload.coffee',
'app/.build/electron': './app/test/electron.coffee'
};
this.nodeOption.entry = {
'app/.build/server': './app/test/server.coffee'
};
this.browserOption.entry = {
'web/.build/client': './web/test/client.coffee'
};
super.start();
}
}
const compiler = new AmCompiler();
compiler.start();