Code Monkey home page Code Monkey logo

just's Introduction

Just

npm version NPM Downloads

Just is a library that organizes build tasks for your JS projects. It consists of:

  • just-task: a build task definition library
  • just-scripts: sane preset build flows for node and browser projects featuring TypeScript, Webpack and Jest

Documentation

All the documentation is online at https://microsoft.github.io/just/

Building

See the contributing instructions.

Packages

Package Description
just-task The task definition library that wraps undertaker and yargs-parser libraries
just-scripts A reusable preset of frequently used tasks in node and browser projects
just-scripts-utils A set of utilities for just-scripts
just-task-logger A shared pretty logger used to display timestamps along with a message

Contributing

This project welcomes contributions and suggestions. Most contributions require you to agree to a Contributor License Agreement (CLA) declaring that you have the right to, and actually do, grant us the rights to use your contribution. For details, visit https://cla.microsoft.com. Please refer Contribution guide for more details

When you submit a pull request, a CLA-bot will automatically determine whether you need to provide a CLA and decorate the PR appropriately (e.g., label, comment). Simply follow the instructions provided by the bot. You will only need to do this once across all repos using our CLA.

This project has adopted the Microsoft Open Source Code of Conduct. For more information see the Code of Conduct FAQ or contact [email protected] with any additional questions or comments.

just's People

Contributors

acoates-ms avatar altinokdarici avatar anikethsaha avatar bworline avatar christiango avatar dannyvv avatar dependabot-preview[bot] avatar dependabot[bot] avatar dotnetjunky avatar dzearing avatar ecraig12345 avatar ian-craig avatar jasongore avatar jasonvmo avatar jugglingjsons avatar kenotron avatar klassm avatar kyledavide avatar micahgodbolt avatar microsoft-github-policy-service[bot] avatar renovate[bot] avatar rlandav avatar scotthysom avatar stanlemon avatar statm avatar thisen avatar tomoya55 avatar tristanwatanabe avatar vipati avatar zzzgit avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

just's Issues

Upgrade to jest 24

just and the templates are currently on jest/ts-jest 23. We should update to 24 at some point. Not sure if there were any blocking issues with 24 or whether it's just a matter of bumping the versions.

Clarify story for modifying a task from a preset

Suppose I want to mostly use the webapp preset as-is, but I want to modify the 'build' task (maybe to build scss or codepen examples before ts). How should I do that?

Related question: how do I know the names of the existing tasks provided by a preset?

Command line arguments example is unclear

The provided example is unclear with the output it's supposed to create.

const { task, logger, option, argv } = require('just-task');

option('name');

task('blimey', 'An exclamation of surprise.', function() {
  logger.info(`blimey! ${argv().name}`);
});

using the suggested command results in the same output for me
command

just --help
just blimey --help

output

Options:
  --help     Show help                                                 [boolean]
  --version  Show version number                                       [boolean]

Shouldn't it be printing something about the name argument? At least denoting it's there and can be used?

I've tried changing the options definition to the following:

option('name', {
  describe: 'description',
  type: 'string'
});

and

option('name', {
  describe: 'description',
  type: 'string'
}).usage("$0 -name string").help();

with no luck - I would expect the arguments to be somehow listed when the --help flag is passed to the task.

Getting started steps don't work

I just tried these steps: https://microsoft.github.io/just/docs/doc-start.

  1. I created a new npm package:
mkdir play
cd play
npm init -y
  1. I installed just-task:
npm install -D just-task
  1. I used VS Code to create a new file "just-task.js" containing:
const { task, option, logger, argv } = require('just-task');

option('name', { default: 'world' });

task('sayhello', function() {
  logger.info(argv().name);
});
  1. Then I tried running the sayhello task:
npx just sayhello

RESULT:

[5:34:29 AM] x Cannot find config file "null". Please create a file called "just-task.js" in the root of the project next to "package.json".

Code from hero image does not work

The code from the hero image on microsoft.github.io/justhere in the source—will not work.

The code uses parallel in the last line but that was never imported.

As per the documentation, the import needs to be changed to:

const { task, option, logger, argv, parallel } = require('just-task');

Tangentially related, I would suggest to replace that image with an actual code snippet. While these hero code images look fancy, they are not accessible at all.

Upgrade template process changes

I am proposing that we take the approach of this:

  1. gather all the commits and replay git diff's from template version to new template version
  2. apply these commits to the existing repo, halting on conflicts
  3. consider adding some upgrade hooks so that codemod can be added later

Add ergonomic way to allow recovery steps to be part of the logger.warn / error

@kevinclement suggestion:

Since you're including logging at part of the framework, it would be nice if it had an easy way to make errors 'pretty', or 'sane' or 'actionable'. [...] map some ridiculous error message into a human readable error, or some error with context. e.g. invalid token. Would be cool if there were a nice ergonomic way to map those cleanly. Could be at the task level or some uber catch.

Dependencies?

Many task runners and build systems allows dependencies between tasks, and runs a task only when needed. Therefore are there any plan to support dependencies?

A nice dependency system comes from SHAKE, a Haskell build system from Neil Mitchell (@ndmitchell), which allows you to build first then add dependencies like this:

"release.tar" %> \_ -> do
    need ["release.txt"]
    files <- lines <$> readFile "release.txt"
    need files
    system "tar" $ ["-cf", "release.tar"] ++ files

The Equivalent in TS:

task("release.tar", async function(target){
    await target.need("release.txt"); // or maybe "this.need"
    const files = lines(await readFile("release.txt"));
    await need(...files);
    await system("tar", ["-cf", "-release.tar", ...files]);
})

Problem with css loader?

I started with an Office Fabric template that uses TypeScript and React and Just. When I tried to add an "import" statement for a .css file into the App.tsx file, I got a compiler error that said I needed a loader. I ended up having to put the following code into my webpack.config.js in order to get it to work. But I'm hoping there is something I did wrong or some simpler setting I can change to get the same effect.

module.exports.module.rules.push( { test: /\.css$/, use: ['style-loader', 'css-loader'], } );
module.exports.resolve.extensions.push('.css');

tscTask crashes when passing no parameters

When creating a minimal script like so:

const { task} = require('just-task');
const { tscTask } = require('just-scripts');

task('typescript', tscTask());

and running npx just typescript, just will crash producing a node core dump:

╰─$ npx just typescript                                                                                                                                                                                                                                            134 ↵
[10:22:02] ■ started 'typescript'
[10:22:02] ■ Running /home/klassm/IdeaProjects/node_modules/typescript/lib/tsc.js with /home/klassm/IdeaProjects//tsconfig.json
[10:22:02] ■ Executing: "/home/klassm/.nvm/versions/node/v10.15.3/bin/node" "/home/klassm/IdeaProjects//node_modules/typescript/lib/tsc.js" --project "/home/klassm/IdeaProjects/t/tsconfig.json"
[10:22:03] ■ finished 'typescript' in 1.66s
╭─klassm@pinguix ~/IdeaProjects/  ‹master*› 
╰─$ npx just typescript
[10:22:29] ■ started 'typescript'
Cannot read property 'project' of undefined
node[14730]: ../src/callback_scope.cc:110:void node::InternalCallbackScope::Close(): Assertion `(env_->execution_async_id()) == (0)' failed.
 1: 0x8dc510 node::Abort() [node]
 2: 0x8dc5e5  [node]
 3: 0x8ac0c7  [node]
 4: 0x8ddbd7 node::InternalMakeCallback(node::Environment*, v8::Local<v8::Object>, v8::Local<v8::Function>, int, v8::Local<v8::Value>*, node::async_context) [node]
 5: 0x8a6569 node::AsyncWrap::MakeCallback(v8::Local<v8::Function>, int, v8::Local<v8::Value>*) [node]
 6: 0x912684 node::fs::FSReqWrap::Resolve(v8::Local<v8::Value>) [node]
 7: 0x914567 node::fs::AfterNoArgs(uv_fs_s*) [node]
 8: 0xa45565  [node]
 9: 0xa498df  [node]
10: 0xa5a5c8  [node]
11: 0xa4a21b uv_run [node]
12: 0x8e6f45 node::Start(v8::Isolate*, node::IsolateData*, std::vector<std::string, std::allocator<std::string> > const&, std::vector<std::string, std::allocator<std::string> > const&) [node]
13: 0x8e5239 node::Start(int, char**) [node]
14: 0x7fb7f4e8fb6b __libc_start_main [/lib/x86_64-linux-gnu/libc.so.6]
15: 0x89ed85  [node]
[1]    14730 abort (core dumped)  npx just typescript

When chaning the typescript task to task('typescript', tscTask({}));, typescript successfully compiles.

[Proposal] : Migrating to yeoman-generator for create-just package

Proposal

package : create-just

Currently, the generating method in create-just package is quite rough and as mentioned by @kenotron it is immature too. There are few issues here and there about copying the generating the packages. What I am suggesting is to migrate the whole create-just to yeoman-generator which is a proven library used by many packages.
The migration a first stage we can just wrap the yeoman over the existing with few refactor to support the package.

Packages Required :

  1. yeoman-environment
  2. types
  3. yeoman-generator

Refactor requires:

  • In https://github.com/microsoft/just/blob/master/packages/create-just/src/index.ts
    need to use the package - Need to set up the environment for the yeoman using yeoman-environment and pass the yargs parsed arguments generator class
  • commands are gonna be same as they are now, need to change the handler method
  • In a new folder https://github.com/microsoft/just/blob/master/packages/create-just/src/generator 👇
  • Based on the arguments(or not if not passed), prompt the existing question and extract the logic of finding the project in a separate method and use it to find the package.
  • Copy the template from them
  • Install the dependency
  • ALL SET

All log messages and utils can be used as they are used now

Rush with pnpm throws error in webpackTask

building using rush and pnpm results in

Error: Cannot find module 'webpack'
    at Function.Module._resolveFilename (module.js:547:15)
    at Function.Module._load (module.js:474:25)
    at Module.require (module.js:596:17)
    at require (internal/module.js:11:18)
    at webpackTask (C:\ossiaco\etorrent\common\temp\node_modules\.registry.npmjs.org\just-scripts\0.12.1\node_modules\just-scripts\lib\tasks\webpackTask.js:20:16)
    at Object.<anonymous> (C:\ossiaco\etorrent\scripts\tasks\webpack.js:8:19)
    at Module._compile (module.js:652:30)
    at Object.Module._extensions..js (module.js:663:10)
    at Module.load (module.js:565:32)
    at tryModuleLoad (module.js:505:12)

No example on command line commands

There is no clear example on how to create a task that executes a command line command.

For example how would you execute a task that starts with "ng build" and then runs some other command line task.

Add Just to Docusaurus Featured Projects List

Hey Everyone,
Docusaurus would like to add this project onto it's display of featured Docusaurus.
basically these are open source projects using docusaurus for setting up their documentation.
(Which is why Just will look perfect up there.)

What I would require would be a logo for the same, which can be linked to the featured projects list on Docusaurus.
So I would need permissions and files for the same, looking forward for some replies to this.

cc and links:
facebook/docusaurus#1080
https://docusaurus.io/en/users

P.S: a sample PR as to how this process occurred for another user
facebook/docusaurus#1275
😃🎉🚀

Featuring just in Docusaurus

Hello, we would like to feature this project to the Docusarus users.

If you are okay with it, can you provide us with a logo?
More information about this issue can be found here here.

Improve story for adding on sass support to webapp preset

Currently if you want to build sass files, you can't just use the webapp task preset, and multiple manual config modifications are required (build, webpack, jest). We should provide an easier way to handle that.

There are two types of scenarios we may want to support for building/bundling sass files:

  1. Webpack: Convert and bundle the files using webpack loaders (some combination of sass-loader, postcss-loader, autoprefixer, css-loader, @microsoft/loader-load-themed-styles). Might still need separate handling for jest.
  2. AMD-compatible: Convert the sass files to ts files first, then load/bundle with AMD (what fabric does today)

We're probably more interested in doing (1) in a reusable manner, since most people are moving away from AMD.

Add prettier support

We should add support for prettier in the templates:

  • Config files (possibly allowing overrides per-project within a monorepo)
  • Pre-commit
  • Extension suggestion in vscode settings

`npm init just` failed on Windows

I tried to initialize a monorepo with Just to transfer some of my old code but it failed.

Forgot escaping spaces?


[9:20:29 PM] ■ Initializing the repo in Z:\......
'C:\Program' is not recognized as an internal or external command,
operable program or batch file.
create-just.js init [name]

Creates a brand new repository

Options:
  --version    Show version number                                     [boolean]
  --help       Show help                                               [boolean]
  --stack, -s  Stack to generate (e.g. just-stack-single-lib,
               just-stack-monorepo)

{ Error: Command failed: C:\Program Files\nodejs\node.exe common/scripts/install-run-rush.js update
    at checkExecSyncError (child_process.js:616:11)
    at Object.execSync (child_process.js:653:13)
    at Object.e.rushUpdate (C:\Users\reli\AppData\Roaming\npm-cache\_npx\6740\node_modules\create-just\dist\cli.js:1:492784)
    at Object.<anonymous> (C:\Users\reli\AppData\Roaming\npm-cache\_npx\6740\node_modules\create-just\dist\cli.js:1:372206)
    at Generator.next (<anonymous>)
    at o (C:\Users\reli\AppData\Roaming\npm-cache\_npx\6740\node_modules\create-just\dist\cli.js:1:370604)
  status: 1,
  signal: null,
  output: [ null, null, null ],
  pid: 10316,
  stdout: null,
  stderr: null }

sass task eats errors

I have an scss file with a malformed import statement. When attempting to compile this file with just, I see an uninformative error. It would appear that nodeSass returns only the first line of the error with the message property, while the actual error resides on further lines. However, the formatted property does include the value.

Expected:

$ npm just-scripts sass
[10:58:33 AM] x Error detected while running 'sass'
[10:58:33 AM] x ------------------------------------
[10:58:33 AM] x src/components/Todo.scss
Error: File to import not found or unreadable: .
        on line 1 of src/components/Todo.scss
>> @import '~office-ui-fabric-react/dist/sass/References';
                    ^
[10:58:33 AM] x ------------------------------------
[10:58:33 AM] x Error previously detected. See above for error messages.

Actual

$ npx just-scripts sass
[10:57:33 AM] ■ started 'sass'
[10:57:33 AM] x Error detected while running 'sass'
[10:57:33 AM] x ------------------------------------
[10:57:33 AM] x src/components/Todo.scss: Error: File to import not found or unreadable: .
[10:57:33 AM] x ------------------------------------
[10:57:33 AM] x Error previously detected. See above for error messages.

Prevent jest from logging regular output to stderr

By default, for some reason jest logs its regular output to stderr rather than stdout. This confuses rush build and causes it to report that the projects in just "succeeded with warnings." Fabric works around this with a custom reporter. We should add a similar reporter for use within the just project and possibly also within the templates.

const DefaultReporter = require('jest-cli/build/reporters/default_reporter').default;

/**
 * The purpose of this custom reporter is to prevent Jest from logging to stderr
 * when there are no errors.
 */
class JestReporter extends DefaultReporter {
  log(message) {
    process.stdout.write(message + '\n');
  }
}

module.exports = JestReporter;

Proposal: Rollup task

I propose adding a task for Rollup.

Rollup is used by many to optimize their libraries and is a solid tool. Webpack doesn't have esm support yet.

npx just gives command not found: just

Expected to use npx as in getting started guide. Instead got:

npx just
npx: installed 1 in 1.55s
command not found: just

Current environment at time of issue:

➜  workspace node -v
v8.12.0
➜  workspace npm -v
6.4.1

Also: using just-task doesn't work either:

npx just-task sayhello
npx: installed 104 in 10.198s
[13:42:22] x Invalid configuration file: /blah/blah/just-task.js
[13:42:22] x Error: Cannot find module 'just-task'

just-stack-single-lib: no jest configuration found, skipping jest

It looks like just-stack-single-lib is not creating a jest config.

After scaffolding a new project, then running npm t, I get:

❯ npm t

> [email protected] test .../just-single
> npx just test

[10:35:23 AM] ■ started 'test'
[10:35:23 AM] ■ started 'clean'
[10:35:23 AM] ■ Removing [lib, temp, dist, coverage, lib-commonjs]
[10:35:23 AM] ■ finished 'clean' in 0.01s
[10:35:23 AM] ■ started 'jest'
[10:35:23 AM] ▲ no jest configuration found, skipping jest
[10:35:23 AM] ■ finished 'jest' in 0s
[10:35:23 AM] ■ finished 'test' in 0.04s

Revisit how to set path of project being added/upgraded

Currently, the way to set the project being operated on by addPackageTask or upgradePackageTask is to set projectPath in just-scripts-utils/paths. It would be clearer to pass the project path as an optional parameter to a task factory instead. (The default would still be process.cwd().)

Warn about missing dependencies

Some specific tasks in just-scripts have peer dependencies which we haven't found a good way to declare (since there is no "optional peer dependencies" field in package.json)--for example, webpackTask requires that the consumer of just-scripts also have webpack installed.

We should establish a pattern for verifying the presence of those dependencies and warning if they're missing. The warning message could possibly also include a recommended version range.

Create webpackCliTask to use webpack-cli

Currently, webpackTask has to take on lots of functionality that is already codified inside webpack-cli package, we should treat webpack's cli as the API surface for this task to simplify the task.

Ensure webpack error output goes to stderr

When doing rush build within the just project, webpack's output seems to be going to stdout rather than stderr even when there's a build error. This makes it next to impossible to see what the build error was in travis builds.

We likely will also need to do the same fix for the templates.

tscTask() does not support mutually exclusive `build` option

For better or worse, TypeScript chose to make the --build CLI parameter mutually exclusive from all other parameters, including the project parameter. Further, TypeScript requires the use of the --build parameter in order to respect the composite: true and/or references options in the tsconfig.json.

This conflicts with Just's current implementation of tscTask(), which always sets the project if it can successfully find the tsconfig.json.

Proposal: If build is true in the options argument to tscTask(), then skip setting the options.project value itself and instead provide the path to the discovered tsConfigFile as documented in https://www.typescriptlang.org/docs/handbook/project-references.html and party on.

Add ability to mix in config when creating a task (webpack, jest, others?)

For certain task factories (especially webpack and jest, maybe others), it should be possible to pass in config options which are mixed in with the defaults. Some possible ways to do this:

  1. If relevant config file exists in the project dir, just loads the file and mixes its options in with defaults
  2. Add a utility in just for merging config with default, then call the utility in each project's relevant config file

We should also consider whether the default config for any tasks could be improved.

Possible inspiration: Fabric's webpack-resources.js and jest-resources.js

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.