Skip to content

Instantly share code, notes, and snippets.

View munificent's full-sized avatar

Bob Nystrom munificent

View GitHub Profile
@munificent
munificent / gist:8700021
Created January 30, 2014 00:12
A new pub command?

I'm starting to work on a new pub command. I've got two goals for it.

Use case 1: Pre-populating your cache (bug #16265)

The first is that it can be used to install a package into your system cache. For example, maybe you're about to go off the grid and you want to make sure you have a bunch of stuff cached locally before you fall off the Internet. pub get does this implicitly, of course, but you may not have any packages that depend on the stuff you're downloading. You just want to pull it down.

Our specific use case is that we are starting to run tests of packages. Since hitting the network can fail, we'd like to do that separately from running pub get so that we can handle the failure more gracefully.

The idea is you could do:

@munificent
munificent / gist:8873127
Last active August 29, 2015 13:56
Assets in "lib"

I spent a bunch of this morning talking with Siggy and Nathan about asset-handling in pub. It's still pretty rough in many places, and we're trying to figure out how to smooth that out. The questions that started this (brought up on this thread) were:

  1. Can you have non-dart files in a lib/ directory?
  2. If so, where do they end up when you run pub build?

Since, I love transparency and feedback, and because many of the constraints pub operates under aren't obvious, I thought it might be cool to walk through our thoughts.

What's with "lib" and "packages"?

When we initially created pub, well before we did any work on assets, the only goal of the system was to be able to re-use Dart code.

@munificent
munificent / gist:8921326
Created February 10, 2014 18:20
Pub serve outside of web/

Spent a bunch of time talking to Nathan, Siggy, and Kevin about how to handle pub serve with stuff outside of web/. Our goals are:

  1. Root-relative URLs inside web/, test/, example/, and even things like subdirectories of example/ should be supported. This means that the root directory being served needs to be constrained to those.

    We can't require the user to hit localhost:8080/example/example1/foo.html because it would break a root-relative URL in foo.html.

  2. More than one of these directories needs to be servable simultaneously. If you have to shut down the server and restart it (which entails rebuilding

someAsyncThing.then((_) => itWorked())
..catchError((error) {
handleError();
});
@munificent
munificent / gist:a56a70c7d5387f65cb8f
Last active August 29, 2015 14:05
How to bump the async_await compiler in the Dart repo

Scenario: Kevin and Erik or some other fine contributor to the async_await package on GitHub has committed some changes and you want to use those within the main Dart repo.

About you:

  • You already have the repo downloaded locally on your machine.
  • You are using Git, not svn. You also probably ride a horseless carriage and no longer use leeches and bloodletting to cure your ailments.

Note that you do not need a separate svn checkout. You already have one, you just don't know it.

Given that, here's the process. This likely alsos work for other third party packages that live on GitHub that we want to use in the Dart repo, but I make no promises there:

library logger;
import 'verbose.dart';
import 'plain.dart';
log(message) {
print(const String.fromEnvironment("logger.level"));
if (const String.fromEnvironment("logger.level") == "verbose") {
logVerbose(message);
} else {
@munificent
munificent / gist:b8f2785c7d1744bdd22f
Created October 29, 2014 18:03
Getters versus fields
// On my laptop, I get:
// getter run 1: 73ms
// getter run 3: 64ms
// getter run 11: 63ms
// getter run 12: 14ms
// getter run 30: 13ms
// field run 1: 68ms
// field run 7: 64ms
// field run 9: 63ms
@munificent
munificent / lexer.wren
Created January 9, 2015 15:13
Start of lexer for Wren in Wren
class Token {
new(type, text) {
_type = type
_text = text
}
type { _type }
text { _text }
toString { _text + " " + _type }
@munificent
munificent / dart2js.diff
Created June 9, 2015 22:50
This is a diff of the changes between formatting dart2js (151303 lines) using the current 0.1.8 version of the formatter and the new rules version.
diff --git a/pkg/compiler/lib/compiler.dart b/pkg/compiler/lib/compiler.dart
index cf68043..80a6c9c 100644
--- a/pkg/compiler/lib/compiler.dart
+++ b/pkg/compiler/lib/compiler.dart
@@ -96,7 +96,8 @@ class CompilationResult {
*/
Future<CompilationResult> compile(Uri script, Uri libraryRoot, Uri packageRoot,
CompilerInputProvider inputProvider, DiagnosticHandler handler,
- [List<String> options = const [], CompilerOutputProvider outputProvider,
+ [List<String> options = const [],
@munificent
munificent / dev_compiler_output.js
Created August 5, 2015 16:33
Dart->JS output on a simple program
dart_library.library('simple', null, /* Imports */[
"dart_runtime/dart",
'dart/core'
], /* Lazy imports */[
], function(exports, dart, core) {
'use strict';
let dartx = dart.dartx;
class Simple extends core.Object {
Simple(name) {
this.name = name;